如果我有一个自定义帖子类型,例如“电影”,我该如何从该自定义帖子类型中回显5个最新帖子。
我试过了
<?php
$type = 'movies';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -5,
'caller_get_posts'=> 5
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
虽然这不返回任何东西
您共享的代码中存在多个语法错误。
要回答您的问题,posts_per_page
应为正整数,并caller_get_posts
应将其删除(几年前已弃用)。
$args=array(
'post_type' => 'movies',
'post_status' => 'publish',
'posts_per_page' => 5,
);
$my_query = new WP_Query($args);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句