dpdrtj1075 2019-02-15 12:14
浏览 111

如何始终首先从搜索结果中显示特定帖子

I created a search filter that displays posts randomly, and I wonder how can I always display a specific post item in the first position of the search results and display the rest of the items normally.

Thank you for your help @dassoun, here is the query :

$taxonomies = array('recipe_type', 'product_category', 'recipe_category', 'recipe_event', 'recipe_diet');
foreach ($taxonomies as $taxonomy) {
    $taxonomies_taxonomy[$taxonomy] = get_taxonomy($taxonomy);
    $taxonomies_terms[$taxonomy] = get_terms(
        array(
        'taxonomy'      => $taxonomy,
        'hide_empty'    => false,
        'meta_key'      => 'filter_order',
        'orderby'       => 'meta_value_num',
        'order'         => 'ASC'
        )
    );
    $taxonomies_selected[$taxonomy] = (get_query_var($taxonomy)) ? get_query_var($taxonomy) : '';
}
  • 写回答

1条回答 默认 最新

  • dongmi1995 2019-02-15 12:31
    关注

    I think you should have a look at the "UNION" operator.

    from https://www.w3schools.com/sql/sql_union.asp: The UNION operator is used to combine the result-set of two or more SELECT statements.

    • Each SELECT statement within UNION must have the same number of columns
    • The columns must also have similar data types
    • The columns in each SELECT statement must also be in the same order

    The idea would be:

    select * from post where (hastobetop = 1 or id = myid or whatever)
    UNION
    yourfilteredrequest
    

    You may have to exlude the rows returned by the first request from the filtered one.

    [edit] Sorry, I hadn't seen it was specific to wordpress [/edit]

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘