Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.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
Php 如何在WordPress中编写帖子ID的WP_查询_Php_Wordpress - Fatal编程技术网

Php 如何在WordPress中编写帖子ID的WP_查询

Php 如何在WordPress中编写帖子ID的WP_查询,php,wordpress,Php,Wordpress,我是WordPress的新手,我正在尝试编写一个循环查询来使用post_id获取帖子 请查找我已尝试的以下代码 $current_query = new WP_Query( [ //'post_type' => 'snippet', 'post__in' => $postids, ] ); 当我试图打印查询和它作为post的post类别时,但当我在数组args中添加相同的类别时,我需要一些特定的类别,它会给我另一个查询,它会给nu

我是WordPress的新手,我正在尝试编写一个循环查询来使用post_id获取帖子

请查找我已尝试的以下代码

$current_query = new WP_Query(
    [
        //'post_type'   => 'snippet',
        'post__in' => $postids,
    ]
);
当我试图打印查询和它作为post的post类别时,但当我在数组args中添加相同的类别时,我需要一些特定的类别,它会给我另一个查询,它会给null。有人能帮我吗?

告诉我们你在哪里(代码)添加了什么,而不是给我们模糊的描述。
$args = array(
    'post_type' => 'snippet',
    'post__in' => array(123, 345, 678)
);

$postsbyid = get_posts($args);

foreach ($postsbyid as $postbyid) :
    //Do something
endforeach;