2757

How to limit post in wp_query

Please anyone help to solve this. I need to limit post in wp_query.

I know how to limit post in wp_query

For example if this page id is 20, I am running the query:

function wpcodex_filter_main_search_post_limits( $limit, $query ) { if ( get_the_ID()==20 ) { return 'LIMIT 0, 12'; } return $limit; } add_filter( 'post_limits', 'wpcodex_filter_main_search_post_limits', 10, 2 );

But I need to set the limt as 25 to 35.

How to do this?

Even if I am placing return 'LIMIT 25, 35'; it is still showing first 35 products, not the posts between 25 to 35.

That query is like: LIMIT 10 OFFSET 15

Please help me.

Answer1:

The answer is… taratata!!!! :

function wpcodex_filter_main_search_post_limits( $limit, $query ) { if ( get_the_ID()==20 ) { return 'LIMIT 25, 10'; } return $limit; } add_filter( 'post_limits', 'wpcodex_filter_main_search_post_limits', 10, 2 );

Because in 'LIMIT 25, 10';, here 25 is the offset and 10 the number of posts to display. So that way it will display 10 products beginning with the product 26…

See this thread: Whats the difference between post_limits and pre_get_posts

Recommend

  • WordPress - Display only Parent Category posts not sub categories posts
  • Appending one array to another array in the same loop
  • Exempting pdf, doc, and xls from screen grab utility
  • Getting WP Functions to Return rather than Printing Immediately
  • How to get the product url in Easy digital download?
  • Get the total stock of all variations from a variable product In Woocommerce
  • Add dynamic data to line chart from mysql database with highcharts
  • Mysql - How to search for 26 records that each begins with the letter of the alphabet?
  • Limiting recursion to certain level - Duplicate rows
  • Test if a set exists before trying to drop it
  • Cancel a live stream “fast motion” catch-up in Flash
  • Algorithm for a smudge tool?
  • Get one-time binding to work for ng-if
  • How do I change content of ComboFieldEditor?
  • Adding a button at the bottom of a table view
  • How can I send an e-mail from a vbs script
  • Using $this when not in object context
  • Spring security and special characters
  • Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel
  • How do I fake an specific browser client when using Java's Net library?
  • Date difference with leap year
  • angularjs unit test when to use $rootScope.$new()
  • Volusion's generic SQL folder, functionality
  • Menu Color Fade on Hover with Jquery
  • How to limit post in wp_query
  • Hazelcast - OperationTimeoutException
  • How to make Safari send if-modified-since header?
  • Adding custom controls to a full screen movie
  • Delete MySQLi record without showing the id in the URL
  • How to set the response of a form post action to a iframe source?
  • Hits per day in Google Big Query
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • Bitwise OR returns boolean when one of operands is nil
  • Is there any way to bind data to data.frame by some index?
  • Django query for large number of relationships
  • reshape alternating columns in less time and using less memory
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?