Use pre_get_posts
to do any alterations of the main query. The main query happens before the template is loaded, using query_posts
just overwrites that original query, which is a waste of resources:
function wpa82795_archives_orderby( $query ) {
if ( $query->is_archive() && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'asc' );
}
}
add_action( 'pre_get_posts', 'wpa82795_archives_orderby' );
See Conditional Tags for other conditions you can test for to limit the application of your new query parameters. You can set any query arguments that are available for WP_Query
.
Related Posts:
- Random sort within an already sorted query
- Exclude posts with specific meta_value while sorting by a separate meta_value
- how to get post order by post id wp_query?
- How to sort WP_Post Object array by object field in php?
- Ajaxify Post Sort
- Sort / Filter Queries
- custom sort posts in archive/taxanomy page
- How to limit the number of posts that WP_Query gets?
- Setting Custom Sort Order of Posts within a Category
- WP_Query offset argument does not work
- Can I force a metabox to be in one column?
- Search by Hyphen
- Exclude drafts in all() view of edit.php
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- Keep getting same permalink with WP_Query?
- How to query posts with current or future date only
- WordPress Number of Posts Not Changing With posts_per_page
- Pagination not working on Custom Page Template
- Create new WordPress post [wp_insert_post] based on results of a WP_Query
- Sort wp post title with alphabetically and numerically?
- Display the latest posts, published in the last hour, with WP_Query
- Custom Order in WP Query
- Fetch posts from current week (Sunday to Saturday)
- Search query – exact post title match
- Converting multiple loops into one single loop with pagination
- How would I get 1 latest post from a query for 5 posts?
- How to get most recent commented post above new submitted post in WordPress?
- Exclude posts with empty post_content in wp_query
- Exclude posts from featuring
- Lazy Load using WP_Query pagination
- Only display a certain number of posts, dependent on how many posts there are available in a query
- Server-side sorting of posts
- AJAX filter posts by year
- Automatic post deletion
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Yearly archive page for future year
- I want to get title name of post, but i didn’t get by this code. Any suggestion?
- How can I show many posts an author has per week?
- Ajax load more button in Recent posts widget
- WP_Query orderby not working with meta_value_num and menu_order
- Custom WP_Query with complex ‘post_status’ argument
- is there a way to show the the post title after the image?
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- Ajaxify This Code
- Select only post id and meta value with WP_Query
- How to : pagination in 3 different custom loops on the same page
- Query Posts by Custom Field
- Using wp_list_pages() after calling query_posts()
- Why are my paginated posts always returning the same results?
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- Loop doesn’t exclude the specified category in home page
- why the same code got different results when using query_posts in functions.php and index.php
- Query posts by Author and/or by Tag
- Migrate posts from category and sub-category via SQL
- How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?
- WP_Query: Show 10 posts in date order, first three random
- Exclude some posts from displaying in wp_query based on some condition
- WordPress Loop: How to display recent posts in multiple divs
- Random posts that always include a particular post?
- Conflict array_splice on loop and query in widget
- WP_Query of Category Not Showing First Post
- Change content off every sixth element
- WP_Query get posts in custom database table [duplicate]
- WP query taxonomy optimization
- WordPress Query – Display 5 posts (same post type), each from a given tag
- While loop in functions.php outputting the_title() of each post on frontpage
- Show posts from two specific category in WP_Query
- How to create loop of posts except post ID defined via ACF field
- Multisite how to display merged posts from two sites and sort by latest date?
- a WordPress connected to 2 database
- WP_Query that targets all categories
- Fill the exclude array() in get_posts()
- Double loop output
- Get current user, change users post status to published
- Displaying a specific sub-category’s posts from wp_query
- Custom layout manager for posts
- Display WordPress Post By Date
- GUID to related post not in current language
- Get results from the main wp_query
- How can I display a specific number of post in a category via a url
- Advanced Post Display/Pagination/Ordering
- Query category-specific, paginated posts and allow viewer to change sort order
- Sorting Posts by Date – get_blogs_of_user_id()
- Pagination for custom query won’t let me back on page 1
- Make assigning post to a specific category equivalent to assigning it to all categories
- WP_Query retrieve custom posts but not the post showing
- How to get alphabetic listing x other posts, based on first letter post?
- How to get single post by one author?
- Sort by category and then date?
- List posts related to category on a div [closed]
- WP_query sort by custom meta_key “price”
- Wp_query WooCommerce products
- posts_per_page – Repeats only first posts ‘post__in’ array
- query_posts different amount of posts per page [duplicate]
- Add custom PHP (no-SQL) filter to WP_query
- How do I get content of custom post type through post ID
- Filter/Sort Post Form On Taxonomy page
- Filters do not work when there are multiple (one works)