Get all posts using WordPress get_posts

By default the WordPress get_posts function will return 5 posts, this code snippet allows you to retrieve all posts according to the other parameters passed in.

In the snippet below we'll get all posts by passing in a '-1' value for the 'posts_per_page' parameter:

$args( 'post_status' => 'publish', 'posts_per_page' => -1);
$posts = get_posts( $args );

Simple as that.

Note, this will return everything so if you're using a custom post type that's going to run into the thousands this isn't likely to be the most efficient way to retrieve data. 

Sign Up

NEXT: Pricing Table Generator

Pricing tables allow you to present the different products or packages you are offering to your customers in a format that will help them to choose which is best for them. In this post we'll look at some inspirational pricing table designs, what to think about when creating your content and a free pricing table generator tool that will save you time creating the markup.

comments powered by Disqus
Sign Up

Popular Tags

350x250

Need a web developer?

If you'd like to work with code synthesis on your next project get in touch via the contact page.