WordPress pre_get_posts 顶帖优先
我需要以下方面的一些帮助。我有一个带有自定义字段“user_define_field”的 WordPress 自定义帖子类型。如果此字段值以“Top”开头,我希望它成为第一个帖子。到目前为止,我想出了这个:
$query->set('meta_query', array(
'relation' => 'OR',
array(
'key' => 'user_defined_field',
'value' => '^Top',
'compare' => 'REGEXP',
'type' => 'STRING'
),
array(
'key' => 'verwaltung_techn-user_defined_simplefield-code',
'compare' => 'NOT EXISTS',
'type' => 'STRING'
),
));
不幸的是,这样它一直在加载,但从不显示结果。仅通过第一个元查询,它就显示了“Top”对象only: 大批( '键' => '用户定义字段', '值' => '^顶部', '比较' => '正则表达式', '类型' => '细绳' ),
另一个元查询也可以单独工作。但是当它们与关系=“OR”组合时,它不起作用。有什么想法吗?
I need a litte help with the following. I have a Wordpress custom post type with the custom field 'user_defined_field'. If this fields value starts with 'Top' I want it to be the first posting. So far I came up with this:
$query->set('meta_query', array(
'relation' => 'OR',
array(
'key' => 'user_defined_field',
'value' => '^Top',
'compare' => 'REGEXP',
'type' => 'STRING'
),
array(
'key' => 'verwaltung_techn-user_defined_simplefield-code',
'compare' => 'NOT EXISTS',
'type' => 'STRING'
),
));
unfortunately like this it keeps loading and it never shows the result. With just the first meta query it shows me the "Top"-Object only:
array(
'key' => 'user_defined_field',
'value' => '^Top',
'compare' => 'REGEXP',
'type' => 'STRING'
),
the other meta query also works by itself. But when they're combined with relation="OR" it does not work. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试在这样的数组中包装或包装案例(未经测试):
You could try wrapping both or cases in an array like this (untested):