Fluffy Potato
Fluffy Potato

Reputation: 3

post_type not working when category_name is set wp_query

When using post_type together with category_name in wp_query, the filtering for the specific post type stops working. How can I filter by both post type and category name?

When I remove the category_name argument, the filtering starts working again.

$args = array(
         'category_name' => 'road,city',
         'post_type' => 'post',
         'post_status' => 'publish',
         'orderby' => 'post_date',
         'posts_per_page' => 2,
         'paged' => $paged
);
$query = new WP_Query($args);

I expect to get posts within the categories 'road' and 'city' but also get pages within those categories. The category query works but not the post_type.

Upvotes: 0

Views: 621

Answers (1)

Unnati
Unnati

Reputation: 358

The posts_type should be working fine. You may try changing for the category. In my case, I have added custom categories in Wordpress using the below lines -

'category__in' => array($category_id1, $category_id2)

Hope this helps.

Upvotes: 0

Related Questions