php - 如何始终首先显示搜索结果中的特定帖子
问题描述
我创建了一个随机显示帖子的搜索过滤器,我想知道如何始终在搜索结果的第一个位置显示特定的帖子项目并正常显示其余项目。
感谢您的帮助@dassoun,这是查询:
$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) : '';
}
解决方案
我认为您应该看看“UNION”运算符。
来自https://www.w3schools.com/sql/sql_union.asp:UNION 运算符用于组合两个或多个 SELECT 语句的结果集。
- UNION 中的每个 SELECT 语句必须具有相同数量的列
- 列还必须具有相似的数据类型
- 每个 SELECT 语句中的列也必须是相同的顺序
这个想法是:
select * from post where (hastobetop = 1 or id = myid or whatever)
UNION
yourfilteredrequest
您可能必须从过滤后的请求中排除第一个请求返回的行。
[编辑]对不起,我没有看到它是特定于 wordpress [/编辑]
推荐阅读
- ruby - Sinatra 根据请求安全地设置时区
- java - 如何找到在 Java 程序中创建的对象的数量?
- sql - 与贷款表的正确关系?
- php - 根据 WooCommerce 中的成本更改运输方式标签名称
- python - 确定哪个打印语句在终端中产生一行输出
- javascript - 如何避免 Jquery 将 `?` 翻译成 `%3F`
- kubernetes - 如何为我的整个集群创建一个入口,该入口可以自动使用 kube-dns 来实现到内部服务的基于路径的路由?
- css - 通过 pandoc&wkhtmltopdf 从 mkd 生成 pdf 时如何使用 css 设置页面/文档边距?
- c++ - 分支可能性提示是否通过函数调用进行?
- ffmpeg - 如何使用 ffmpeg 调整 h264 视频的大小?