Note that here you’re overriding the paging of the main query, with the posts_limits
filter, by using hardcoded values:
'LIMIT 0, 25'
where 0
is the offset and 25
is the number of posts to display.
So in this case I would just use pre_get_posts
with
$query->set( 'posts_per_page', 25 );
and we don’t have to worry about the paging.
If i wanted to return 5 posts conditionally without paginating the
remainder, would i use post_limits or pre_get_posts?
If we later decide that pagination is necessary, then we would need to rework your posts_limits
code. The pre_get_posts
filter would work as is and we could therefore say that it’s at least a more “future proofed” method.
Another thing: If you were using get_posts()
or WP_Query()
with suppressed filters, then the posts_limits
filter wouldn’t be available while the pre_get_posts
hook would be accessible.
Related Posts:
- How to filter sql only for a specific post type
- WP_Query with “post_title LIKE ‘something%'”?
- How to add taxonomy filter on the query fly?
- Changing Posts Per Page and offset with pre_get_posts
- Is it possible to select against a post’s parent’s fields with WP_Query?
- Ignore a filter on the media library
- How to make an activities stream mixing posts and comments?
- SQL query equivalent to WP User Query
- Which filter/action hook gets triggered after a query has been performed?
- Advanced WP Query hogs the SQL server
- Remove ellipsis from the excerpt retrieved using get_the_excerpt()
- SELECT * FROM $wpdb->posts WHERE ID > 160
- Removing posts from the returned wp_query. Cannot use object of type WP_Query as array
- Use ‘parse_query’ filter to show posts that from multiple criteria
- Query post with meta_query where date is not in future
- What is considered a default query for the request filter?
- Using apply_filters(‘the_content’, $custom_query->post_content) alters output
- Modifying the Search Results
- Query total number of posts
- How to add post_distinct filter to WP_Comment_Query?
- How To Fix WP Query Returns Results But Shouldn’t?
- Using Ajax to load more posts | Help me change the wording on my button to notify the user
- List of the years with posts presented
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- Slow WP_Query for custom post type
- Complex WP SQL Query
- Optional Meta Query
- Order by title without taking into account ‘the’
- Sorting events by descending date, and ascending time if multiple events on a date
- Editing the default wordpress search
- How to filter, restrict and return posts based on custom user meta information
- Filter posts in category archive page by year using a dropdown
- How to extract specific post
- Woocommerce – Changing the order of the upsell products [closed]
- Changing sort order for presentation by Jetpack infinite scroll
- Applying posts_clauses filter to specific queries only
- Add class to first post in custom loop using post_class filter
- Include data from custom table in WP_Query
- Add posts to WP Query object
- how to access query string in wordpress?
- Filter Custom Taxonomy Posts
- Debugging wp_query orderby for taxonomy
- Is it possible to query from external database? [duplicate]
- Include posts from some categories while excluding from others
- Include post content of linked posts in search
- Make a SQL query with wpdb in WordPress
- List of ways to access WordPress database?
- Filter post query to only show direct children of category
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Getting rid of unwanted nonSQL syntax characters when debugging a query
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Change AJAX filter from POST to GET for URL Parameters
- Using post_where filter only on main query NOT sidebard new WP_Query
- Filtering posts by archive showing all years
- Query where ANDing slug values not working
- WP_Query – How to get all posts of specific days of week by custom field date?
- Multiple wp_query on archive page
- Retrieve select tag custom values from array and display them in current page with wp_query?
- How to use a dropdown to filter posts by custom field
- Remove post type filter added by the plugin in the final query
- relation OR instead of AND – Filtered term ID’s in loop
- Can’t order the query result as given posts id’s array
- How to avoid filling up an array each time I run a WP_query?
- How to SQL query posts IDs by categories AND authors?
- filter posts by meta key with pagination
- Why does apply_filters behave different inside and outside a loop?
- Custom post type – filter content by custom meta box content
- Filter sub-category from checkbox form
- My combination of ‘post_type’ and ‘tax_query’ not working?
- SQL query injection with fifu image
- How to add a “base” filter for all posts visible to visitors on the site?
- WP Query – grouping posts by same meta key, adding together values from another key
- What is the equivalent WP_Query of a SQL Query?
- WordPress – Form does not filter the results of taxonomies
- Translating WP query into to SQL query
- Query Posts | Combining multiple form inputs into query arguments to generate one filter result
- Sorting query_posts() with a complex orderby filter
- Filtering posts for unique titles, only the most recent
- WP Query filters active on wrong query
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- How to search CPTs in draft using get_page_by_title()
- Custom category page with taxonomy filters
- Gather same custom field values in one value in a select tag with wp_query
- WP_Query doesn’t works inside loop
- Track write actions to the database
- What argument does my function need to echo get_results() query results
- Fetch only categorized posts
- Add filter to Orderby Parameter using Array
- Custom WP_Query with SQL directives for getting posts by authors and terms
- query post based on comparison
- How to return value from sql and display it
- orderby in WP_query doesn’t works
- Do not show a custom post if it belongs to a certain custom taxonomy
- Convert a WP Query into a simpler SQL query to fetch only COUNT of posts
- wp_query->set for several categories
- Adding arguments to WooCommerce Product Loop using AJAX
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Add custom argument to WP_Query and modify SQL where clause
- I need to get all categories from a WP_Query
- Group By query based on Custom Field