Is it possible to retrieve post entry for a custom post type by tag, I have been trying with the following code, however it just locks me into a infinte loop.

<aside class="supporting_images">
    <?php /*<?php if($post->ID == 241) : echo apply_filters('the_content', '[slideshow=3]'); endif;  ?>
    <?php the_post_thumbnail(); ?>*/?>

    <?php if($post->ID == 241) : ?>
        <?php
            $query = new WP_Query();
            $query->query('tag=branding');
        ?>
        <?php while ($query->have_posts()) : ?>
            hello
        <?php endwhile; ?>
    <?php endif;?>

3 s
3

You’ll need to setup the post for the query by changing the following line to get rid of the infinite loop.

<?php while ($query->have_posts()) : $query->the_post(); ?>

If your looking for a custom post type, you’ll need to specify that in the query arguments:

<?php $query = new WP_Query( array( "post-type" => "yourposttype", "tag" => "branding" ) ); ?>

You can see most (if not all) of the query parameters in the codex. http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *