list posts alphabetically in tag archive
-
I am trying to have my archive page for tags deliver an alphabetized list of posts. I am using code suggested elsewhere in these pages thus:
function wpsf_orderby( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; // do conditional checks here and return on false.? if ( is_category( ) ) { remove_action( 'pre_get_posts', __FUNCTION__ ); add_filter( 'posts_orderby', function() { return ' post_title ASC'; } ); } } add_action( 'pre_get_posts', 'wpsf_orderby' );But I keep getting the error
Fatal error: Call to a member function is_main_query() on a non-object
relating to the line
if ( is_admin() || ! $query->is_main_query() )Any clues? I have a parent category used in the code above, plus child categories and I also have tags assigned to each post, some of which are the same for different posts. I am using a child theme based on twentyfourteen with this code added into my functions.php file with a call to the function in tag.php, also in the child theme folder.
The topic ‘list posts alphabetically in tag archive’ is closed to new replies.