Not able to get posts based on category
-
Hi,
I have tried using WP_Query to get all posts that belong to a certain category.
I have created a custom post type that I use to create posts, and I also set a specific category for each post (posts of the same post type belong to different categories, to be displayed grouped by cat in sections on the same page).This is the code I’m using (using multiple loops, with different category IDs):
$args = array( 'category' => 25, 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1, 'post_type' => 'my_post_type', 'post_status' => 'publish', ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ...
The loop works but shows all posts of that post type, ignoring the ‘category’.
If I only use ‘category’ => 25 and leave out ‘post_type’ => ‘my_post_type’ I get nothing.
(Also tried ‘category’ => ’25’).Any help is much appreciated!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Not able to get posts based on category’ is closed to new replies.