I’m trying to query a custom post type ‘section’ where the ‘section.section_parent_page = {whatever the ID of the current $post is}’.
This part of the query works fine and is accomplished like this:
$args = array(
'post_type' => 'section',
'meta_query' => array(
array(
'key' => 'section_parent_page', // name of custom relate field
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
);
But once I try to ‘orderby’ the custom field ‘section_position’, I either break the query or see no proper ordering. Here’s what I currently have:
$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'
)
)
);
When I look at the $the_query->request, it looks like it continues to order by wp_posts.menu_order
How do I use multiple meta_query arrays to accomplish this?
EDIT:
No matter what I try, the end of my query string ends up looking like this:
ORDER BY wp_posts.menu_order ASC LIMIT 0, 10
If section_position has integer ( number ) value, use following code
Note i have used “meta_value_num” instead of “meta_value”
I attempted to do the same thing recently within an ACF filter. I contacted ACF support and received this answer.