我最近從頭開始創建一個wordpress電影網站,其中我現在發現很難清除不工作的代碼。 我有的問題是我有一個自定義帖子類型「電影」和一些自定義元數據附加到前面提到的帖子類型,我想要做的是列出我的自定義帖子類型「電影」順序元數據「發佈」。這是我的functions.php文件的一部分。
add_filter('rwmb_meta_boxes', 'your_prefix_meta_boxes');
function your_prefix_meta_boxes($meta_boxes) {
$meta_boxes[] = array(
'title' => __('Movie Meta Box', 'textdomain'),
'post_types' => 'movies',
'fields' => array(
array(
'id' => 'name',
'name' => __('Title', 'textdomain'),
'type' => 'text',
),
array(
'id' => 'released',
'name' => __('Release Date', 'textdomain'),
'type' => 'date',
),
array(
'id' => 'rating',
'name' => __('Rating', 'textdomain'),
'type' => 'radio',
'options' => array(
'0' => __('Unrated', 'textdomain'),
'1' => __('1', 'textdomain'),
'2' => __('2', 'textdomain'),
'3' => __('3', 'textdomain'),
'4' => __('4', 'textdomain'),
'5' => __('5', 'textdomain'),
'6' => __('6', 'textdomain'),
'7' => __('7', 'textdomain'),
'8' => __('8', 'textdomain'),
'9' => __('9', 'textdomain'),
'10' => __('10', 'textdomain'),
),
),
array(
'id' => 'duration',
'name' => __('Duration', 'textdomain'),
'type' => 'text',
),
array(
'id' => 'genre',
'name' => __('Genre', 'textdomain'),
'type' => 'textarea',
),
array(
'id' => 'director',
'name' => __('Director/s', 'textdomain'),
'type' => 'textarea',
),
array(
'id' => 'writer',
'name' => __('Writer/s', 'textdomain'),
'type' => 'textarea',
),
array(
'id' => 'stars',
'name' => __('Star/s', 'textdomain'),
'type' => 'textarea',
),
array(
'id' => 'storyline',
'name' => __('Storyline', 'textdomain'),
'type' => 'textarea',
),
),
);
return $meta_boxes;
}
這是檔案館,movies.php
<?php get_header(); ?>
<?php bd_pagination(); ?>
<div class="row" role="main"><!-- ROW -->
<?php
$args = array(
"posts_per_page" => 10,
"post_type" => "movies",
"post_status" => "publish",
"meta_key" => "released",
"orderby" => "meta_value_num",
"order" => "DESC"
);
$wp_query = new WP_Query($args);
?>
<?php if ($wp_query->have_posts()) : ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="col-lg-9">
<div class="panel panel-default panel-body" style="padding-bottom:0;"><!-- PANEL -->
<p class="fa fa-calendar"></p> <?php the_time('d-m-Y'); ?> | <p class="fa fa-clock-o"></p> <?php the_time('H:i a'); ?> | <p class="fa fa-user"></p> <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><?php the_author(); ?></a></i> | <p class="fa fa-envelope-o"></p> posted in movies
<article class="post <?php if (has_post_thumbnail()) { ?>has-thumbnail <?php } ?>">
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('image-poster'); ?></a>
</div>
<article class="post-thumbnail-text">
<h4 class="align_Center" style="color:#000; padding-bottom:1em;">
<?php the_title(); ?>
</h4>
<?php
$nam = get_post_meta(get_the_ID(), "name", true);
$rel = get_post_meta(get_the_ID(), "released", true);
$rat = get_post_meta(get_the_ID(), "rating", true);
$dur = get_post_meta(get_the_ID(), "duration", true);
$gen = get_post_meta(get_the_ID(), "genre", true);
$dir = get_post_meta(get_the_ID(), "director", true);
$wri = get_post_meta(get_the_ID(), "writer", true);
$sta = get_post_meta(get_the_ID(), "stars", true);
$sto = get_post_meta(get_the_ID(), "storyline", true);
?>
<div class="align_Left">
<p><b>Title:</b> <?php echo $nam; ?></p>
<p><b>Released:</b> <?php echo $rel; ?></p>
<p><b>Rating:</b> <?php echo $rat; ?>/10</p>
<p><b>Duration:</b> <?php echo $dur; ?> min</p>
<p><b>Genre:</b> <?php echo $gen; ?></p>
<p><b>Director/s:</b> <?php echo $dir; ?></p>
<p><b>Writer/s:</b> <?php echo $wri; ?></p>
<p><b>Stars:</b> <?php echo $sta; ?></p>
</div>
</article>
</article>
<br>
<div class="panel panel-default panel-body" style="padding:20px 20px 10px 20px">
<p><b>Storyline:</b> <?php echo $sto; ?></p>
</div>
</div><!-- /PANEL -->
</div>
<?php endwhile; ?>
<?php else : echo '<p>NO CONTENT FOUND</p>'; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div><!-- /ROW -->
<?php bd_pagination(); ?>
<br>
</div><!-- ./CONTAINER -->
<?php get_template_part('Secondfooter'); ?>
<?php get_footer(); ?>
希望有人能幫助我..一直@好幾個星期。
在此先感謝
你嘗試使用meta_value代替meta_value_num查詢? –
這個問題很可能出現在你的保存元框功能中,你在數組中指定了日期來設置日期,但是如果你檢查數據庫後期元,它可能保存爲文本格式,你需要轉換爲時間戳('strtotime ()'應該可以) – David