WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


    function filter_where_categs() {
        $where .= " AND (category_name => array('black-star-crescent-moon', 'audio', 'blackward', 'ghost', 'protect', 'remember', 'return', 'video'))";
        return $where;

        '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');

share|improve this question
are you using the default category taxonomy for all your custom post types? – Jan Beck Aug 4 '12 at 10:51

According to the codex category_name only takes one string value. category_in accepts an array of category IDs:

$args = array(
 'category__in' = array(1,4,6,8), // use IDs
 'post_type'=> array( $ptype, 'post', 'test-btum', 'test-other' )
$wp_query = new WP_Query($args); ?>

It might be possible that the default category taxonomy is not registered to your custom post type. In that case try adding

register_taxonomy_for_object_type( 'category', 'test-btum' )

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.

share|improve this answer
Please add some explanation. Thanks. – kaiser Aug 4 '12 at 10:53
@JanBeck. thanks. category_in yielded the same results as category_name, which i tried after this question. so it works. but it is not giving me the results that i need. it returned posts for the 'post' post type only and not for any other post type. so your previous question is important. i'm not sure if i'm using default category taxonimoies. when i looked at the categories i needed for all the post types, all post types have exactly the same categories, they all had the same ID. i'm using a theme that has an interface that creates custom post types and their respective categories. – user1569898 Aug 5 '12 at 2:34
@JanBeck.thanks again. register_taxonomy_for_object_type didn't change the results. still only getting posts from blog that match the cat ID's – user1569898 Aug 16 '12 at 23:27
@JanBeck. thanks again. register_taxonomy_for_object_type yielded posts from blog that match the cat ID's. is this function supposed to add a meta box with the Blog categories in the other custom post types? – user1569898 Aug 16 '12 at 23:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.