Wordpress limiit query results

How can I limit query result in wordpress let's say I want to display just 4 last posts from a category but starting from second row, I know that in MySql is like this:

select * 
from table_name 
limit 4, 1

In wordpress should be something like this:

('cat' => get_category_id($catname), 'posts_per_page' => 2, 1);

But it is not working


I found the solution, i just needed to use the offset variable instead of paged.

Check here for details


Use the paged (and the $paged WordPress variable) argument. All info here : http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query

Tags: Mysql / Wordpress

Similar questions

Style WordPress search results based upon custom post type results
On my site I have a few different custom post types which I have enabled to show up in search results. I was wondering how you could Query / Style each custom post type result differently. For example if I was to do a search that pulled results from my blog articles and also my custom post type called cards which is a list of cards I would like to ...
Wordpress Search Results show results which is broken link
The site search is showing the result correctly for some reason the link for the result is broken. Example This is what I get from the search results. In fact the link should have been going to the following page. From the admin, I have entered this information's under posts with categories. Here's the PHP Code (I don't think anything is wrong with...
Add results into WordPress search results
I would like to add/inject/append extra results into the WordPress search results. At the moment WordPress only allows you to "adjust" the query that is being executed on its own database, but doesn't allow you to modify (or in WordPress lingo, filter) the results array. I.e: If in WordPress I search for the term 'potato' all posts related to this ...
Custom wordpress results page invidual results are listed from the bottom up(opposite dynamic code). How can I change this?
I am using in my header. And the code that is dynamically produced lists the items from top to bottom but they show up bottom to top and going into my banner. I can only control where the bottom (first) result lands on the page so moving it down to create room would be useless if the search only brought back a few results. I have tried to set the h...
Combine Wordpress site search results with product search results on one page
On my Wordpress website, a site search that is limited to only posts renders a perfect results display of posts. A product search also renders a perfect display of products, although displayed differently. But if I attempt to search for both posts and products, the display is terrible. I think the products are probably forced into the posts display...
Custom Post Type: Search Results - Template for no results
My custom-post-type is a Property Listing and on the Homepage there is a Search form. The Search Form works fine if there is a Property or Properties Matching the results. If there are no Properties matching their Search then for some reason it drops my custom-post-type page and it uses index.php to display a page. The URL structure is like this: T...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.