我制作了一个名为movies
的自定义帖子类型,并添加了一个电影元框,其中包含一些我希望在帖子中看到的关于我要添加到存档的电影的选项。
问题是我可以在一个帖子中查看所有元信息,但不能查看我在single-movie.php
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="panel panel-default panel-body">
<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 } ?> clearfix">
<article class="post-thumbnail">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('image-poster'); ?></a>
</article>
<article class="post-thumbnail-text">
<h4 class="align_Center" style="color:#000; padding-bottom:1em;"><?php the_title(); ?></h4>
<?php $posts = get_posts(array(
'post_type' => 'movies',
'post_status' => 'publish',
'posts_per_page' => -1,
'fields' => 'ids'
)
);
$nam = get_post_meta( $posts, "name", true );
$rel = get_post_meta( $posts, "released", true );
$rat = get_post_meta( $posts, "rating", true );
$dur = get_post_meta( $posts, "duration", true );
$gen = get_post_meta( $posts, "genrer", true );
$dir = get_post_meta( $posts, "director", true );
$wri = get_post_meta( $posts, "writer", true );
$sta = get_post_meta( $posts, "stars", true );
$sto = get_post_meta( $posts, "storyline", true );
?>
<div class="align_Left">
<p>Title:</p> <?php echo $nam; ?><br>
<p>Released:</p> <?php echo $rel; ?><br>
<p>Rating:</p> <?php echo $rat; ?><br>
<p>Duration:</p> <?php echo $dur; ?><br>
<p>Genre:</p> <?php echo $gen; ?><br>
<p>Director:</p> <?php echo $dir; ?><br>
<p>Writer:</p> <?php echo $wri; ?><br>
<p>Stars:</p> <?php echo $sta; ?><br>
<p>Storyline:</p> <?php echo $sto; ?>
</div>
</article>
</article>
</div>
<?php endwhile;
else :
echo '<p>NO CONTENT FOUND</p>';
endif; ?>
</div><!-- ./CONTAINER -->
<?php get_footer(); ?>
答案 0 :(得分:0)
get_posts()
返回的帖子数量不仅仅有一个帖子。第一个参数的get_post_meta()
需要单个帖子的ID而不是帖子数组&#39; IDS。
您需要做的是创建循环,例如:
foreach ( $posts as $post ) : setup_postdata( $post );
$name = get_post_meta( get_the_ID(), "name", true ); ?>
...
<p>Title:</p> <?php echo $nam; ?><br>
...
<?php
endforeach;
wp_reset_postdata();