douke1891 2015-11-19 13:07
浏览 54

如何在Wp_query中包含一个帖子?

My current query looks like this.

$tag_id = 276;
$tag = get_tag($tag_id);
$today = date( "Y-m-d" );

$args  = array(
    'post_type'     => array(
                        'post',
                        'review',
                        'cardguide'
                    ),
    'taxonomy'      => 'post_tag',
    'tag_id'        => $tag_id,
    'posts_per_page'=> - 1,
    'orderby'       => 'id',
    'order'         => 'DESC',

    'meta_key'      => 'event_end_date',
    'meta_query'    => array(
        'relation'=> 'AND',
        array(
            'key'    => 'event_start_date',
            'value'  => $today,
            'compare'=> '<=',
            'type'   => 'DATE'
        ),
        array(
            'key'    => 'event_end_date',
            'value'  => $today,
            'compare'=> '>=',
            'type'   => 'DATE'
        )
    )

);
$my_query = new Wp_query( $args );

I want to include a single post (can use post id) into this query. The post may not obey each of the rules I defined inside $args. And also would like to have it always on top of the list (featured item).

  • 写回答

1条回答 默认 最新

  • duanchi6377 2015-11-19 19:40
    关注

    If you are looking to get the same post by id for this query every time, then just do a separate get_post() call like:

    $featured_item = get_post( 123 ); // replace 123 with your id
    

    This will prevent you from having to worry about "obeying each of the rules" you've defined above. Plus, if you always want it "on top", then you can pump out the values of $featured_item before you run your query loop.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测