Display all custom taxonomy posts and sort alphabetically
-
Hey folks!
I want to display all my custom posts within a taxonomy and also list them alphabetically. I don’t want to change the setting: Reading > Blog posts show at most.
After searching, I’ve found this custom function code (added to functions.php) to make it work …
function customize_directory_listings ( $query ) { if (($query->is_main_query()) && (is_tax('resource_category'))) $query->set( 'posts_per_page', -1 ); $query->set( 'orderby', 'title' ); $query->set( 'order', 'ASC' ); } add_action( 'pre_get_posts', 'customize_directory_listings', 1 );
However, this also has the effect of displaying every post on every page in alphabetical order – even the posts in the Admin area. I can’t figure out why it’s doing that when the function specifically calls for
is_tax
Does anyone know;
a) why that’s happening, and
b) how to fix it so it only shows on the custom taxonomy page (taxonomy-resource_category.php)Here’s my site in case it helps understand what I’m trying to do. It’s the Resources section: https://whistlerweddingmagazine.com/resource-category/venues/
As you can see it works, but it also works for the main posts too which is not what I want.
Thanks!
- The topic ‘Display all custom taxonomy posts and sort alphabetically’ is closed to new replies.