dongqiao9015 2016-01-11 23:15
浏览 13

按时间顺序显示合并的Wordpress查询

How can I get the actual $first_ids to display first and then show $second_ids. With this code, it still orders them. Not sure what they are ordered by, I am guessing Wordpress defualt sorting?

What I am trying to achieve is that I added the tag "Featured" to all posts inside a custom post type "aircraft-refueling" and I want to display all the "Featured" posts first and then show the rest of the posts.

<?php
// first query
$first_ids = get_posts( array(
    'fields'         => 'ids',
    'posts_per_page' => '999',
    'post_status'    => 'publish',
    'post_type'      => array('aircraft-refueling'),
    'tag' => 'featured'
));

// second query
$second_ids = get_posts( array(
    'fields'         => 'ids',
    'posts_per_page' => '999',
    'post_status'    => 'publish',
    'post_type'      => array('aircraft-refueling'),
    'tag__not_in' => array('592')
));

// merging ids
$post_ids = array_merge( $first_ids, $second_ids);

// the main query
$query = new WP_Query(array(
    'post_type' => 'aircraft-refueling',
    'post__in'  => $post_ids, 
    'paged'     => $paged
));
?>
  • 写回答

1条回答 默认 最新

  • doushi4795 2016-01-11 23:27
    关注

    I figured it out. After you merge the queries, on the third one you have to add

    'orderby' => 'post__in', // Preserve post ID order given in the post__in array (available since Version 3.5).
    

    and that puts the posts in the order that it retrieved in from the merged post array.

    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图