Order By with have_post wordpress


Order By with have_post wordpress

我有一些帖子id数组的id对我有更高的优先级。

现在在列出所有的帖子,我希望数组id应该首先出现,然后所有其他的id张贴。

我为这个顺序设置了逻辑,就像我有两个id(15,19)的数组,然后我想要这两个帖子,然后其他所有id帖子应该来。

我的逻辑在下面,它运行良好。

按大小写排序当id IN(15,19) THEN 0其他的id

但是我如何添加这个逻辑与have_posts循环顺序。

请帮帮我。

快速思考,我会做两个循环,一个是你想要固定在开始的帖子,第二个是其他的帖子,像这样:

 $fixed = array(8,14); 
 //gets only the posts with IDs 8 and 14
    $fixed_args = array(
        'post__in' => $fixed
    );
    $fixed_query = new WP_Query($fixed_args);
    if($fixed_query->have_posts()){
        while ($fixed_query->have_posts()){
            $fixed_query->the_post();
            the_title();
            the_content();                
        }
    }
    //excludes the posts with IDs 8 and 14
    $query_args = array(
        'post__not_in' => $fixed
    );
    $the_query = new WP_Query($query_args); 
    if($the_query->have_posts()){
        while ($the_query->have_posts()){
            $the_query->the_post();   
            the_title();
            the_content();     
        }
    }

我不知道是否有办法在一个简单的循环中做到这一点,但我会查看它并更新,如果我发现任何