Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to get all posts that have a specific tag, regardless of what type of post that is. I've tried every solution I've found (here on SO and further), but nothing works: I always only get the normal 'post' type from my wp_query.

I've tried this:

$query_args = array(
        'tag' => $tag,
        'post_type' => array('post', 'praktijk', 'expert', 'download', 'product', 'event')
    );

    $query = new WP_Query( $query_args );

And I would think that would work. Replacing the array of post_types with the string 'any' also doesn't work.

Does anybody know what I'm doing wrong?

share|improve this question
    
Code and syntax appear correct. Do you actually have CPTs tagged with $tag? –  Johannes Pille Nov 27 '12 at 11:12
    
Hm. I re-created all tags and now it seems to work.. Still don't know why.. –  Sander Bruggeman Nov 27 '12 at 11:24

1 Answer 1

You could use

$query_args = array(
    'tag' => $tag,
    'post_type' => 'any',
);
$query = new WP_Query( $query_args );

Please have a look here: Tag Parameters and Type Parameters.

share|improve this answer

Your Answer

 
discard

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.