1

i am using wp_query to get posts for a custom post type but it is only returning the most recently posted item. This is both in the returned object and within the loop:

$wp_query = new WP_Query('post_type=events');

Any ideas what is happening?

  • Do not use $wp_query as variable, you are breaking the main query object. Also, the query defaults to the radingnsetting in back end when it comes to posts per page. If you need any other amount of posts, you explicitely need to set the posts_per_page parameter – Pieter Goosen Jul 13 '15 at 8:32
0

Using $wp_query as your variable is a bad idea as it is something WordPress uses itself. For returning as many results as you would like you can use posts_per_page in your query. There are many more parameters you can query with in WordPress.

$custom_wp_query = new WP_Query('posts_per_page=10&post_type=events');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.