**TLDR** – *After manually updating a custom post, my WP_Query will change it’s sorting order and move that updated post to the end of the array response.*
I have a custom post type called Events that use Advanced Custom Fields. I have written a shortcode that uses WP_Query to find all the Events that are Open and then sort them by their final_deadline first and their priority second.
Here are the arguments for my query: `
$today_is = date(‘Y-m-d’, time());
$the_open_query = new WP_Query($open_events_args);
$open_events = $the_open_query->get_posts(); `
Many of my advanced custom fields are being set programmatically through an API call. What I found was the WP_Query initially returned correct results, but as soon as I manually updated an event post (without changing any of the fields), that post would move to the end of the $open_events array and be out of order.
If I updated another post, it too would move to the end of the array. Eventually the open_events array was bifurcated. The first section had events that were not manually updated, and the second section had events that were updated … and each section was in the correct order.
I went ahead and manually updated my 17 events and figured that would fix it. However, now that I’m adding images to a new advanced custom field, this process is starting all over again. Updated events are moving to the end of the array and out of order.
Does anyone know what would cause this and how I can fix it? Updating an unrelated custom field should not be affecting my WP_Query, but it keeps happening and I’m not sure why.
Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users