As already stated, you should never use query_posts
as it breaks the main query and many functionalities that other code and plugins rely on
Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination).
Also, you should never replace the main query with a custom one. This raises more issues that solving the one you have tried to solve in the first place. Read this post on this issue
This all being said, you are going to make use of pre_get_posts
to alter the main query to change the order of posts to be sorted by title. Then you are going to use parse_tax_query
to remove the child categories from the category pages
You can do something like in your functions.php
add_action( 'pre_get_posts', function ( $q )
{
if ( ! is_admin()
&& $q->is_main_query()
&& $q->is_category()
) {
/*
* Set the order so that posts are ordered by post title
*/
$q->set( 'orderby', 'title' );
$q->set( 'order', 'ASC' );
/*
* Ignore sticky posts, this is the correct syntax to use
*/
$q->set( 'ignore_sticky_posts', true );
/*
* Filter the tax query to remove child categories from category pages
*/
add_filter( 'parse_tax_query', function ( $q )
{
if ( $q->is_main_query()
) {
$q->tax_query->queries[0]['include_children'] = 0;
}
});
}
});
Also, as already pointed out, caller_get_posts
is depreciated and is replaced by ignore_sticky_posts
.
Lastly, your category.php
should look something like this
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
// Your HTML Mark up and template tags etc
}
}