wp query – How to get posts that have certain meta key value and order based on another meta key’s value
Question
Here is the code I gathered off the internet so far:
$args = array(
'post_status' => 'publish',
'posts_per_page' => '5000',
'post_type' => 'post',
'meta_query' => array(
'relation' => 'AND',
'is_part_of_series' => array(
'key' => 'epic-series-select-series',
'value' => $series_id,
'compare' => '=',
),
'chapter_order' => array(
'key' => 'epic-series-chapter-number',
'compare' => 'EXISTS',
)
),
'orderby' => array(
'chapter_order' => 'ASC',
),
);
but for some reason, this gets the correct 3 posts plus some other posts – which I have no idea why are present. I checked the meta table in MySQL
and only the correct 3 posts have the meta key with the value I am querying. Apparently, I am doing something wrong in the query! Any ideas?
I tried asking ChatGPT
for help but it did not.
0
2 weeks
2023-05-17T05:20:22-05:00
2023-05-17T05:20:22-05:00 0 Answers
0 views
0
Leave an answer