如何通过邮寄id wp_Query获得邮购?

时间:2018-07-31 作者:Bhautik

我有4篇帖子,每页显示2篇帖子。

$ids = array(\'16085\',\'16088\',\'16083\',\'16091\');

$options = array(
        \'post_type\' => $post_type,
        \'posts_per_page\' => $posts_per_page,
        \'paged\'     => $paged,
        \'meta_query\' => $meta_query,
        \'tax_query\' => $tax_query,
        \'post__in \' => $ids,
        \'orderby\' => \'post__in\',
);
$get_properties = new WP_Query( $options ); 
我想按给定的$ids数组的特定顺序显示帖子。

2 个回复
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成

好的,那么您想自己定义帖子顺序。WP\\U查询允许您这样做-您必须使用orderby => post__in 实现它。你就是这么做的。

那它为什么不起作用呢?因为输入错误;)

按订购帖子post__in 保留“post\\uu in”数组中给定的post ID顺序。但你不能通过post__in 查询中的参数(您通过post__in - 末端的额外空间)。

$ids = array(\'16085\',\'16088\',\'16083\',\'16091\');

$options = array(
    \'post_type\' => $post_type,
    \'posts_per_page\' => $posts_per_page,
    \'paged\'     => $paged,
    \'meta_query\' => $meta_query,
    \'tax_query\' => $tax_query,
    \'post__in \' => $ids, // <-- here is the additional space
    \'orderby\' => \'post__in\',
);
$get_properties = new WP_Query( $options ); 
所以这应该很好:

$ids = array(\'16085\',\'16088\',\'16083\',\'16091\');

$options = array(
    \'post_type\' => $post_type,
    \'posts_per_page\' => $posts_per_page,
    \'paged\' => $paged,
    \'meta_query\' => $meta_query,
    \'tax_query\' => $tax_query,
    \'post__in\' => $ids, // <-- there is no space anymore in here
    \'orderby\' => \'post__in\',
);
$get_properties = new WP_Query( $options ); 

SO网友:VinothRaja

尝试以下代码

$get_properties = new WP_Query( array( \'post_type\' => \'page\',\'posts_per_page\' => $posts_per_page,\'paged\' => $paged,\'meta_query\' => $meta_query,\'tax_query\' => $tax_query, \'post__in\' => array( 32, 30, 27, 45) ,\'orderby\' => \'post__in\' )  );


echo "<pre>";print_r($get_properties);exit;

结束