I need to get post from blog, custom post type 1, custom post type 2. custom post type 3 and either from category 1 or category 2 or category 3 or category 4 or category 5 or category 6 or category 7 or category 8. I have this but isn’t working. I get no results, no errors either.
<?php
function filter_where_categs() {
$where .= " AND (category_name => array('black-star-crescent-moon', 'audio', 'blackward', 'ghost', 'protect', 'remember', 'return', 'video'))";
return $where;
}
$args=array(
'post_type'=> array( 'test-bscm', 'post', 'test-btum', 'test-other' ),
'posts_per_page' => 19
);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
add_filter('posts_where', 'filter_where_categs');
$wp_query->query($args);
?>
According to the codex category_name only takes one string value.
category_in
accepts an array of category IDs:It might be possible that the default category taxonomy is not registered to your custom post type. In that case try adding
to your themes
functions.php
. Repeat for every post type you want to register. Make sure your custom post types are actually assigned to a category otherwise they won’t show up in your query.