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:
please help if you can
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:
please help if you can
Share Improve this question edited Oct 13, 2019 at 8:32 Jacob Peattie 44.2k10 gold badges50 silver badges64 bronze badges asked Oct 12, 2019 at 9:19 Tom ConnellTom Connell 11 bronze badge1 Answer
Reset to default 0You 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' );