Major issue with my search queries being outputted incorrectly on the blog page with respect to query's. In wordpress admin most relevant listed first but outputted DESC on page.

I have this code in funtions,php

function change_posts_order( $query ) {
if ( $query-is_home() && $query-is_main_query() ) {
$query-set( 'orderby', 'title' );
$query-set( 'order', 'ASC' );

add_action( 'pre_get_posts', ' change_posts_order ' );

Bt it does not work - I have removed all plugins on page except jetpack and akismet: Still no joy. PhP returns these related errors:php error message

please help if you can

1 Answer 1


You have extra spaces around change_posts_order, inside the quotes:

add_action( 'pre_get_posts', ' change_posts_order ' );

PHP can’t find a function with that name, because wits looking for that function preceded with the spaces. Remove the spaces to fix the issue:

add_action( 'pre_get_posts', 'change_posts_order' );
  • thankyou for that and well spotted! I think it might have solved the issue indeed, the PHP warning has gone but it is a little hard to tell - some queries return the same and others as they should. Does SQL cache queries at all because it seems past queries are returned false and newer ones as they should be. I have purged server and browser cache and search in incog so it looks like a caching issue now is responsible for these mixed results... a little more investigation needed my end but happy to have removed the PHP warning and appearing to get on track here - thanks Oct 13, 2019 at 8:12
  • It's probably not working at all. $query-is_home() and $query-is_main_query() are missing the >. They need to be $query->is_home() and $query->is_main_query(). So the ones that worked were probably just a coincidence. Oct 13, 2019 at 8:32
  • thanks for this but still same issue - are posts and custom post types dealt considered the same? or do I need to change the function taxonomy? apologies, I am a real novice and your help is highly appreciated Oct 13, 2019 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.