Php Wordpress元查询不使用';订购人';-高级自定义字段
我试图查询一个自定义帖子类型'section',其中'section.section\u parent\u page={无论当前$post的ID是什么}。 查询的这一部分工作正常,完成方式如下:Php Wordpress元查询不使用';订购人';-高级自定义字段,php,mysql,wordpress,Php,Mysql,Wordpress,我试图查询一个自定义帖子类型'section',其中'section.section\u parent\u page={无论当前$post的ID是什么}。 查询的这一部分工作正常,完成方式如下: $args = array( 'post_type' => 'section', 'meta_query' => array( array( 'key' => 'section_parent_page', // name of c
$args = array(
'post_type' => 'section',
'meta_query' => array(
array(
'key' => 'section_parent_page', // name of custom relate field
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
);
ORDER BY wp_posts.menu_order ASC LIMIT 0, 10
但是,一旦我尝试“orderby”自定义字段“section_position”,我要么中断查询,要么看不到正确的排序。以下是我目前拥有的:
$args = array(
'post_type' => 'section',
'meta_key' => 'section_position', // custom field I want to order by
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'section_parent_page', // name of custom relate field
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
);
当我查看$the\u query->request时,它似乎继续按wp\u posts.menu\u顺序排序
如何使用多个meta_查询数组来实现这一点
编辑:
无论我尝试了什么,查询字符串的结尾都是这样的:
$args = array(
'post_type' => 'section',
'meta_query' => array(
array(
'key' => 'section_parent_page', // name of custom relate field
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
);
ORDER BY wp_posts.menu_order ASC LIMIT 0, 10
如果节_位置具有整数(数字)值,请使用以下代码
$args = array('post_type' => 'section',
'orderby' => 'meta_value_num',
'meta_key' => 'section_position',
'order'=>'ASC',
'meta_query' => array(
array(
'key' => 'section_parent_page', // name of custom relate field
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
);
注意:我使用了“meta_value_num”而不是“meta_value”我最近尝试在ACF过滤器中做同样的事情。我联系了ACF支持部门并收到了此答复 不幸的是,我认为这个查询太复杂,无法通过WP_查询传递,您必须执行手动SQL查询才能实现这一点。 问题是您正在执行两个meta_查询,meta_key=start date,括号内的两个相互冲突。 您需要完整SQL语法的灵活性来执行这样的查询
也许这是我尝试添加“pre_get_posts”过滤器的诀窍,只是为了指向404.php页面……我也尝试过,但没有成功。两个查询字符串似乎都忽略了我的'orderby'子句,仍然输出:orderby wp\u posts.menu\u ORDER ASC LIMIT 0,10