If you’re altering the main query, always use pre_get_posts
to alter query parameters before the query is run and before the template is loaded. This will be the most efficient and will not break pagination. As of v4, orderby
accepts an array of arguments, which gives you the ability to have different order
for each if necessary:
function my_get_posts( $query ){
if( !is_admin() && $query->is_category() && $query->is_main_query() ){
$query->set( 'posts_per_page', -1 ); // show all posts
$query->set( 'orderby', array('menu_order' => 'ASC', 'title' => 'ASC') );
}
}
add_action( 'pre_get_posts', 'my_get_posts' );
Related Posts:
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- Why is it necessary to call rewind_posts() when using the loop more than once? [duplicate]
- Multiple posts with one loop iteration
- Post Loop not Returning Permalink
- How to Loop within a Loop (Display Children and then Grandchildren)
- Exclude first 2 posts with meta_key from loop
- Better way to display posts from specific categories, in a grid layout
- popular post weekly and monthly
- 3 Posts in Loop, Show Stickies First
- Query last updated posts (posts updated in the last 24 hours)
- Displaying terms based on loop posts?
- Duplicated posts on category page
- Make blog page show 10 on first page, 9 on every other page
- How to display posts by vote count and if no value continue with latest posts with no votes?
- query_posts() vs get_posts() multiple loops [duplicate]
- Exclude first post (sticky or not) from the loop using query_posts()
- Pagination not working in category listing [duplicate]
- How can I improve the performance of this query_posts loop?
- Adding div after every two post on main loop! Why will first post not get counted?
- How can I access specific posts brought back by query_posts?
- Separate First Post Loop
- Query posts only with actual text content (not including shortcode or images)
- query_posts clarification needed
- Exclude current post ID from loop in sidepbar.php
- Why does my WP_Query pagination on a custom page.php only loads the homepage?
- Get a Post Loop based on Logged in User information into a Shortcode
- how to add 4 post in one carousel slide
- Query counting excluded category on paged loop
- get_posts and wp_autop (remove filter)
- query_posts ignores the argument
- The Loop isn’t working
- Twitter bootstrap carousel multiple items in carousel
- show posts from one category with comments only
- Least Number of Loops to Create Custom Homepage?
- How to do query_posts on tags pages
- Limitless amount of posts in custom archive page
- How do I get the attributes of a short code from a post?
- WordPress category & taxonomy loop with pagination
- Changing behavior of the loop twice in one page
- post__in – Placing content from a foreach loop inside of an array
- loop query exclude meta_key with meta_value
- “Blog pages show at most” in The Loop
- wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!
- Displaying child page content of a certain parent
- add_filter() doesn’t work in loop
- Content/Excerpt length control for a specific loop?
- Why we use if with while loop?
- How would I get 1 latest post from a query for 5 posts?
- Loop posts only excluding first post
- Loop repeating design pattern
- Sort Posts By Category?
- Create a loop that gets pages with their template
- Why is my loop not dynamically grabbing the correct Category and displaying all categorized posts?
- Query posts if meta key starts with
- Loop within a loop (Again) for template
- How to use current_post to open a new unordered list every five posts
- sticky post in custom loop
- Rating system and changing the loop
- Blog post per page setting conflicting with custom WP_Query?
- Ajax Button to load more Posts into a timeline
- How to target thumbnails of the first post in the loop
- Problem getting current post tags to show in a widget
- Add leading zero to current post display [closed]
- Output meta into arrays
- get_posts output always same post
- Pagination on category.php and tag.php not working
- Moving wordpress to different url/server creates redirect loop
- Pulling in featured image into default recent posts widget
- WP_Query: Show 10 posts in date order, first three random
- Modify loop output for a specific list of categories
- Print the whole page?
- Pagination for two loops
- Loop info in jquery Tabs – loop into a variable?
- Custom Post Type Query W/Category Dropdown
- Thumbnail Image Rounded Corners w CSS (or any other good method)
- Several loops in sidebar issues
- Create a Loop with Posts Ordered by Most Recent Comments
- Adding $args to wp_schedule_event() causes hook to add infinitely to WP Cron
- $post is undefined in wordpress loop [ajax]
- Insert content above an embedded video inside Wordress’ php the_content
- the loop printing post in one grid
- Check value of post meta within IF statement
- My WordPress installation doesn’t load correct template
- Work arounds for conditional checks inside the loop in search.php?
- query_posts() doesn’t seem to be called in my page
- Get Sticky User in user loop based on user role
- Popular posts with Varnish ESI
- Querying posts from only one category and exluding the latest post
- WP update_post_meta link loop
- Need some help with “the_widget()” function
- Conditional Check in The Loop’s Parameters
- Exclude Authors based off date of last post
- WordPress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page
- Loop from another WP site onto mine
- Having issue with WordPress loop
- Wrap every 2 divs in row – for each loop [closed]
- How to add class to the last image of the last post in a loop
- How to exclude certain portfolios from a loop
- I make sticky post for my archive page for custom post type with ACF field and loop is not working