3

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?

  • 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.. – Terrabythia Nov 27 '12 at 11:24
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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