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
- How do you get the count of posts in an archive page?
- Change permalinks for posts but not for custom post types
- Assign single template to multiple custom post types?
- How to show Y number of custom posts after every X normal posts?
- How to build a complex page structure
- Archive page…limiting posts per page
- Adding custom post type to loop
- How can I fix those issues generated by the Themecheck plugin
- Why is get_post_format() for “Standard” returns empty
- Password-protect a custom rss feed
- Rename a current used post type
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- Taxonomy posts on Archive page
- How to show related posts by category or custom post type?
- adding .current* tags to custom post types and taxonomies
- Posts navigation in custom post type single.php not working
- Page as a child of a Custom Post Type
- Display custom field of specific post where post title matches variable
- Remove duplicated values from a loop
- How to connect two custom post types with nested loops
- Normal pages as children of my Custom Post Type
- Custom Post Type Loop throws 500 error when used in widget
- Help need making decision. Ads rotating site on wordpress
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Group CPT posts by custom taxonomy
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Display a grid of taxonomy terms at root taxonomy page
- Display Custom Taxonomy Alphabetically
- Problem: wp_query outputs all images on site
- The loop seems stuck to a single (now deleted) post
- Custom Post Types strange pagination problem
- Display related custom taxonomy posts in sidebar
- Targeting custom post type
- Warning: Invalid argument supplied for foreach() [closed]
- Custom post type isn’t working
- Conditional for a Single Post That Belongs to a Category?
- Getting Un Wanted Gallery Shortcode In The Page on Loop
- Using wp_query to modify the loop in index.php for a CPT
- Query & the_content() is showing in the header
- Listing custom post types on archive page with array
- looping though custom post types and only return results in a given taxonomy
- How to conditionally add Custom Post Type to Front Page
- Pagination not working on custom query on a page
- Show Taxonomies with admin area for custom post type?
- Pagination doesnt work in custom post type
- get custom post type value in header.php [closed]
- get_terms() parent, child and grandchild
- pre_get_posts works in post type archive but not in single post
- Custom PT, Taxonomys and wordpress query
- How can i loop through custom post type according to custom meta field?
- Changing WordPress sort order for returned child pages
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Not Able to Add New Class To CPT Attachment Image
- Fetch data from two custom post types and create multidimensional array for output to html table
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- How to get the custom post data using post id in WordPress?
- Pin posts to top of custom loop
- Custom post type 404 category page
- programmatically generated custom post type is created more than once
- Accessing download link from the loop with WP Download Manager Pro
- Custom WordPress theme not displaying posts from category
- Combine multiple separate lists into one
- custom post type single page
- call a function when insert and update a custom post type
- How to prevent post to repeat on my loop?
- Custom post types not displaying per category
- How To Display Category list from Portfolio post type plugin?
- How to show Y number of custom posts after every X normal posts?
- Search form to find custom meta box generated data
- Load different template for CPT (in loop) in my plugin?
- How to loop custom post type posts by author?
- Why is my custom form saving with ‘autodraft’ as title and slug?
- Inserting random posts
- Custom Loop and Standard Blog Loop Issue
- Custom loop won’t work, can’t find problem
- Categories and page filtering with pre_get_posts
- Loop through multiple custom taxonomy terms and display posts for a custom post type
- loop through custom post-type with two meta_keys
- Loop to pull content from parent element in custom post type [duplicate]
- How to exclude certain portfolios from a loop