Query posts by taxonomy term name

I would love to get the list of posts by their custom taxonomy (=store) name.

Here is what I have so far, but it is not working.

Read More

Please help with the code.

$mystorename is a variable holding the name of the store i want to query by.

Any help will be appreciated.

Thank you

$args = array(
    'tax_query' => array(
    array(
        'taxonomy' => 'store',
        'field' => 'name',
        'terms' => $mystorename
    )
)
);

$postslist = get_posts( $args );if(count($postslist) > 0){ ?>

Related posts

Leave a Reply

3 comments

  1. I’m not sure if the get_posts function supports the tax_query. You might want to try creating a new WP_Query object instead.

    $args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'store',
            'field' => 'name',
            'terms' => $mystorename
            )
        )
    );
    
    $query = new WP_Query($args);
    if ( $query -> have_posts() ) : while ( $query -> have_posts() ) : $query -> the_post(); ?>
        <!-- post -->
    <?php endwhile; ?>
        <!-- post navigation -->
    <?php else: ?>
        <!-- no posts found -->
    <?php endif; ?>
    
  2.  <?php
     $args=array(
      'store' => $mystoreslug,
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {?>
    
     <div class="itembox">
     <h1>Store Coupons</h1>
    
    <div class="itemboxinner">
    
     <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
       <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php         the_title_attribute(); ?>"><h3><?php the_title(); ?></h3></a></p>
      <?php
     endwhile;
    }
    wp_reset_query();  
    ?>'