【问题标题】:How to write WP_query for the post ids in WordPress如何在 WordPress 中为帖子 ID 编写 WP_query
【发布时间】:2019-11-12 13:16:40
【问题描述】:

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

请找到我尝试过的以下代码。

$current_query = new WP_Query(
    [
        //'post_type'   => 'snippet',
        'post__in' => $postids,
    ]
);

当我尝试打印查询和它作为帖子的帖子类别时,但我想要一些特定的类别,当我在数组 args 中添加相同的类别时,它给了我其他查询,它给出了 null。有人可以帮我解决这个问题吗?

【问题讨论】:

  • 向我们展示您实际添加的内容(代码),而不是给我们模糊的描述。

标签: php wordpress


【解决方案1】:
$args = array(
    'post_type' => 'snippet',
    'post__in' => array(123, 345, 678)
);

$postsbyid = get_posts($args);

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 2013-05-19
    • 1970-01-01
    • 2017-06-12
    • 2014-06-11
    相关资源
    最近更新 更多