【问题标题】:wordpress query for pages with arrays not working带有数组的页面的wordpress查询不起作用
【发布时间】:2015-07-09 10:19:26
【问题描述】:

您好,我正在尝试使用查询从 wordpress 中获取几页。

当我这样做时

$query= new WP_Query('page_id=5880');

一切正常

然而,

$query = new WP_Query( array( 'post_type' => 'page', 'page_id' => array( 5880, 5840 ) ) );

什么都不生产。请问我错过了什么?

【问题讨论】:

    标签: php templates wordpress-theming wordpress


    【解决方案1】:

    应该是post__in,而不是page_id

    $query = new WP_Query( array( 'post_type' => 'page', 'post__in' => array( 5880, 5840 ) ) );
    

    https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters

    【讨论】:

    • 谢谢 - 这行得通。假设我有点被 page_id 所吸引,认为如果你将 post_type 设置为 page,那么由于 page_id 说“使用页面 id”,它会给你那些页面。显然不是!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    • 2020-03-30
    • 2012-10-29
    相关资源
    最近更新 更多