• Resolved Hakkelaar

    (@hakkelaar)


    Dear folks,

    I would like to sort the posts on the tag-pages alphabetically, but leave the sorting-order on the homepage unaltered.

    The function that I use now also alters the homepage sort-order.

    function my_post_queries( $query ) {
    	// not an admin page and is the main query
    	if ( !is_admin() && $query->is_main_query() ) {
    		//$query->set( 'posts_per_page', 5 );
    		$query->set( 'orderby', 'title' );
    		$query->set( 'order', 'ASC' );
    	}
    }
    add_action( 'pre_get_posts', 'my_post_queries' );
Viewing 1 replies (of 1 total)
  • Thread Starter Hakkelaar

    (@hakkelaar)

    Ok I solved this.

    All I had to do is change the code to this:

    function my_post_queries( $query ) {
    	// not an admin page and is the main query
    	if ( !is_admin() && $query->is_main_query() && !$query->is_home()) {
    		//$query->set( 'posts_per_page', 5 );
    		$query->set( 'orderby', 'title' );
    		$query->set( 'order', 'ASC' );
    	}
    }
    add_action( 'pre_get_posts', 'my_post_queries' );
Viewing 1 replies (of 1 total)
  • The topic ‘Sort posts alphabetically on the tag-page ónly (in twentysixteen)’ is closed to new replies.