Posts Widget: Current query, order by title
-
I’m creating a glossary of terms on a website, and using a custom post type (Glossary) and custom taxonomy (Letters). I need the posts in these archives to be ordered by title, instead of by date.
On the archive template I’m using a posts widget with ‘current query’. By default the posts are ordered by date and there is no option to change the order (all options are removed with Current Query).
So I’ve set up a custom query to order the posts by title, instead of by date. However, I cannot seem to get it work.
My code is:
add_action( 'elementor/query/pre_get_posts', function ( $query ) { if ( ! is_admin() && $query->is_archive() && $query->is_main_query() ) { if ( get_query_var( 'post_type' ) == 'glossary' ) { $query->set( 'category_name', 'letter' ); $query->set( 'posts_per_page', -1 ); $query->set( 'order', 'ASC' ); $query->set( 'orderby', 'title' ); }; }; } );
Can anyone help? Is there a bug with my code, or is there a bug with the Elementor posts widget?
The page I need help with: [log in to see the link]
- The topic ‘Posts Widget: Current query, order by title’ is closed to new replies.