Wordpress wp_get_recent_posts()按id排除特定帖子
我正在尝试获取最近的两篇文章,但是我想通过id[365]排除特定的文章。有人能帮我吗?这是我的密码Wordpress wp_get_recent_posts()按id排除特定帖子,wordpress,post,Wordpress,Post,我正在尝试获取最近的两篇文章,但是我想通过id[365]排除特定的文章。有人能帮我吗?这是我的密码 $args = array( 'numberposts' => '2' , 'post__not_in' => array( '365' ) ); $recent_posts = wp_get_recent_posts( $args ); <?php foreach($recent_posts as $post):?> <a href="<?php e
$args = array( 'numberposts' => '2' , 'post__not_in' => array( '365' ) );
$recent_posts = wp_get_recent_posts( $args );
<?php foreach($recent_posts as $post):?>
<a href="<?php echo $post['guid']?>"><p><?php echo $post['post_title'];?></p></a>
<?php endforeach;?>
$args=array('numberposts'=>'2','post\u not\u in'=>array('365');
$recent_posts=wp_get_recent_posts($args);
您应该再次调用该函数。您有一个exclude
参数可用:
$args = array( 'numberposts' => '2' , 'exclude' => 365 );
wp\u get\u recent\u posts不支持
post\u not\u in
参数,您需要使用exclude
参考链接
只需将您的代码替换为下面提到的代码,您将获得所需的结果:
<?php $my_args = array('post_type' => 'post' , 'numberposts' => '2' , 'exclude' => '365' );
$my_recent_posts = wp_get_recent_posts( $my_args );?>
<?php foreach($my_recent_posts as $my_post):?>
<a href="<?php echo $my_post['guid']?>"><p><?php echo $my_post['post_title'];?></p></a>
<?php endforeach;?>
<?php $my_args = array('post_type' => 'post' , 'numberposts' => '2' , 'exclude' => '365' );
$my_recent_posts = wp_get_recent_posts( $my_args );?>
<?php foreach($my_recent_posts as $my_post):?>
<a href="<?php echo $my_post['guid']?>"><p><?php echo $my_post['post_title'];?></p></a>
<?php endforeach;?>