Query get_posts by Category ID returns nothing
-
In my template, I am trying to get posts by a custom taxonomy ID with custom post type associated with it.
<?php global $post; $tmp_post = $post; $args = array( 'category' => 20 ); $posts_array = get_posts ( $args ); print_r($posts_array); foreach ( $posts_array as $post ) : setup_postdata( $post ); ?> HTML CODE FOR EACH POST <?php endforeach; wp_reset_postdata(); $post = $tmp_post; ?>
$posts_array is empty with Category ID of 20 (custom taxonomy), but works for any other standard taxonomy category done through the normal taxonomy creator in WordPress.
Is this happening because the custom posts I have created are not yet associated with the custom taxonomy when this get_posts executes?
Also – if I remove category from the args array and specify my ‘post-type’ rather, I get back posts. But I need posts from a specific category, not just narrowed down to the post type.
Any Ideas?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Query get_posts by Category ID returns nothing’ is closed to new replies.