• Hi! Can someone tell me what’s wrong with my code? I’m trying to call posts that belong to a certain post taxonomy only but all the other posts are displayed:

    <?php $args = array(
    'tax_query' => array(
    array(
    'taxonomy' => 'post_taxomony',
    'field' => 'id',
    'terms' => '7'
    )
    )
    );
    $query = new WP_Query( $args ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="testimonialImg"><div class="testimonialImgBorder">
    <?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
    the_post_thumbnail( array(100,100) );
    	}
    ?></div></div>
    <div class="testimonialTxt"><?php the_content(); ?></div>
    <?php endwhile; else: ?>
    <p><?php _e('No posts found.'); ?></p>
    <?php endif; ?>

    Thanks! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try changing this:

    $query = new WP_Query( $args ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    to this:

    query_posts( $args ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    Thread Starter Hazel Z.

    (@cadencehart)

    Thank you so much! That worked! Do you happen to know what should be the right code if I want to call up pages in a certain page taxonomy? I originally wanted this to be a page taxonomy but instead of the pages, the posts show up so I decided to make it a post taxonomy instead. Thanks. 🙂

    Moderator keesiemeijer

    (@keesiemeijer)

    By default Pages don’t have categories or tags so I don’t know what you want. maybe this: http://codex.wordpress.org/Function_Reference/get_pages

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘All Posts are shown even when querying only a certain post taxonomy’ is closed to new replies.