Use the parse_query
hook to override the default main query:
add_action( 'parse_query', function ( WP_Query $wp_query ) {
/**
* Only apply our custom ordering when:
* - We're not in the admin
* - It's an archive (i.e. not singular)
* - It's the main query (won't affect custom WP_Query)
*/
if ( ! is_admin() && ! $wp_query->is_singular() && $wp_query->is_main_query() ) {
$wp_query->set( 'orderby', 'title' );
$wp_query->set( 'order', 'DESC' );
}
});
This needs to live in a plugin or your theme’s functions.php
.
Related Posts:
- Group search results by post type, but hide post types with no results
- Integrating Orbit slider into wordpress through custom post type
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Return the latest post from a custom Taxonomy and Post Type
- Custom WP_Query doesn’t display all posts
- Two column layout with alphabetical ordering
- WP_Query with custom post type ID
- Assign a template to a custom post type when displayed by the main loop on the home page
- Custom Post type content within a slider
- How to display posts from a certain category in a bootstrap 5 carousel loop with multiple items?
- Loop all post on single.php
- Add extra elements to the_post in a custom post_type
- Custom Post Type has wrong label and is not found when called by a loop
- 2 custom posts types, in their own columns, one pagination for both
- Custom post type with custom taxonomy permalinks
- Custom taxonomy page template
- Cant insert wrapper div into index.php
- Create custom post order (with custom post type meta)
- How to create custom page templates with default page layout framework?
- WordPress search results grouped by post type
- Loop custom taxonomy to get lists of cutom post types?
- How do i calculate the total of values of custom fields in custom post types?
- Get term name and term parent into custom post type permalink
- Multiple Loops On Custom Post Type Template?
- Custom loop with multiple taxonomy queries
- I would like to have different styles for my posts based on the content of each post
- Checking if Post Title is Unique as Loop Criteria
- Custom post type not displaying content from single-{custom post type} page
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Custom post type multiple loop by taxonomy term
- Help need making decision. Ads rotating site on wordpress
- List custom taxonomy specific to one custom post type
- Query & Order posts by custom fields
- Show a Category X’s custom post type on Category X archive page?
- Paging doesn’t work?
- Sort by alphabetical order archive.php page
- custom taxonamy and post type
- Custom Tag Description unable to display just below and outside of the Loop
- Display all taxonomy terms, add class if term applies to current post
- Don’t know how to show custom taxonomies from a custom post_type
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Group CPT posts by custom taxonomy
- Not Able to Get Custom Post Type Gallery Images URL
- JS innerhtml changing style when using AJAX
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Best way to style first post differently?
- A to Z List of Custom Post Type in three columns
- Display a grid of taxonomy terms at root taxonomy page
- Custom post type, organized by categories
- What’s the WP way to load remaining custom posts?
- How to Upload CSV Data into Custom Post Type Data with Metabox programmatically
- How to change the post type a theme shows by default?
- Get unique superset of taxonomy terms from a list of custom posts in another hierarchical taxonomy
- WP Query with categories only shows one post and ignores the category
- What to and how to proceed with CPT to make DB small and efficient?
- Post ID randomly printing on page
- A custom post within a custom post
- Display Custom Taxonomy Alphabetically
- Full Custom Post Type List Organised by two Taxonomies
- Event Custom Post Type Title show by upcoming Event Dates
- Displaying Custom Posts on a Page
- Shortcode not working with post counter
- How to have this permalink structure: post_type/postname/custom_inner_page
- Problem: wp_query outputs all images on site
- Get custom post type’s fields in a while loop as variables
- Building a Treatments Page, What Do I Use?
- Custom Post Type within the Loop on Homepage (Page Template)
- The loop seems stuck to a single (now deleted) post
- Posts per row on archive page (custom post type)
- How do I know the ‘meta_key’ for ordering my custom post type
- Custom Theme With Custom Loops
- Custom Post Types strange pagination problem
- Custom post types and category archive
- Custom post type conditional in loop
- custom comments form for custom post type
- Listing all term items alphabetically / sorting loop
- How to produce a sub-page-system in WordPress
- Display related custom taxonomy posts in sidebar
- WebP Fallback for Inline Background Image in Style Attribute
- pagination not working for category.php (custom post types in categories)
- Only show posts with date of today or in the future (i.e don’t show past posts)?
- How do I control the output of a custom post type in the loop?
- Display custom post type posts first, then default posts
- Custom Post Type Category Link
- How to specify a template for a path like http://example.com/something?
- Custom Post type category pages template and loop
- Three Most Recent Posts, One Per Term
- Targeting custom post type
- Does WP have a global of $id?
- WordPress Loop if/else
- get_the_title() is returning results from previous loop
- Warning: Invalid argument supplied for foreach() [closed]
- Custom Post Loop pulling all custom posts, not just one
- Custom post type isn’t working
- Conditional for a Single Post That Belongs to a Category?
- Wrapping x posts in html without leaving empty html
- WP Query post__in not returning correct results
- Custom Post Type single.php template only shows the latest post
- Sort posts in loop by the WooCommerce Membership of the author
- Warning: Invalid argument supplied for foreach() in post.php [closed]