intuitive-custom-post-order
intuitive-custom-post-order copied to clipboard
Doing WP_Query on Ajax Requests
If a wp_query is called via an ajax request on a post type with a custom order it will force the menu_order on the order by param as well as the order to ASC.
The reason being is on line 614 is_admin() does the check to see if the user is on the dashboard or not. Problem is an ajax call in wordpress will treat is_admin as true, if if the user is not even logged in. I have switched it up slightly so on line 614 its now.
if ( is_admin() && !wp_doing_ajax() ) {
This seems to be working for me. I can still order posts but can also pass custom order params via ajax.
Had this issue today. Thanks for this!
I had the same problem!
Only instead of changing the plugin you can do this in the ajax function where you use Wp_Query:
// Set $_GET['orderby'] to whatever you like.
$orderby = $_GET['orderby'] = 'title';
$query_args = array(
'post_type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => 20,
'paged' => $paged,
'orderby' => $orderby,
'order' => 'ASC'
);
$query = new WP_Query($query_args);
Intuitive Custom post order is checking if this $_GET['orderby'] is set before if makes the WP_Query changes. So this way you do not need to worry about plugin updates :D
I had the same problem!
Only instead of changing the plugin you can do this in the ajax function where you use Wp_Query:
// Set $_GET['orderby'] to whatever you like. $orderby = $_GET['orderby'] = 'title'; $query_args = array( 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => 20, 'paged' => $paged, 'orderby' => $orderby, 'order' => 'ASC' ); $query = new WP_Query($query_args);
Intuitive Custom post order is checking if this $_GET['orderby'] is set before if makes the WP_Query changes. So this way you do not need to worry about plugin updates :D
Thank you for this! Looked for a long time before figuring out it was a combination of ICPO and doing an ajax call that was overriding the orderby paramteres.
@harryatkins is this still relevant and can you maybe create a PR with a fix?