Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress wp_get_recent_posts()按id排除特定帖子_Wordpress_Post - Fatal编程技术网

Wordpress wp_get_recent_posts()按id排除特定帖子

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

我正在尝试获取最近的两篇文章,但是我想通过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 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;?>