I have this strange issue. I want to fetch all posts that are of a custom type, here's my snippet.
$query = new WP_Query(array( 'post_type' => 'custom', 'post_status' => 'publish' )); while ($query->have_posts()) { $query->the_post(); $post_id = get_the_ID(); echo $post_id; echo "<br>"; } wp_reset_query();
This only gets me 6 of them, while I have more than 50 records matching that criteria in the database. Can anyone tell me where I have gone wrong?
Many thanks!
'posts_per_page' => -1, Add this to the WP_QUERY array of arguments and it should return all of the posts of this custom post type.
First, you can simply go to Appearance » Menus and add a custom link to your menu. This custom link is the link to your custom post type. Don't forget to replace 'example.com' with your own domain name and 'movies' with your custom post type name.
As so: $args = array( 'post_type' => 'post', 'posts_per_page' => -1, 'order' => $sort_by, 'orderby' => 'title', 'post_status' => 'publish', 'tag' => $tags, 'ignore_sticky_posts' => 1, ); This will make Query get all posts in your table.
Now, if you want to display all your posts from a specific category on a separate page, WordPress already takes care of this for you. To find the category page, you simply need to go to Posts » Categories » View page and click on the 'View' link below a category.
'posts_per_page' => -1,
Add this to the WP_QUERY array of arguments and it should return all of the posts of this custom post type.
This get all posts of a custom type using get_posts
:
$posts = get_posts([ 'post_type' => 'custom', 'post_status' => 'publish', 'numberposts' => -1 // 'order' => 'ASC' ]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With