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 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.

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){ ?>
share|improve this question
add comment

3 Answers

How about...

$args = array(
    'store' => $mystorename,
);
$postslist = query_posts( $args );
wp_reset_query();
share|improve this answer
2  
Explain why that could solve the problem. –  toscho Dec 7 '12 at 15:44
    
Query posts should be used last resort, use get_posts instead. Should $mystorename be a slug, id, display name? explain –  AlxVallejo Dec 17 '12 at 17:16
add comment
 <?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();  
?>'
share|improve this answer
add comment

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; ?>
share|improve this answer
    
the query you posted above kept giving me an error ("expected )") on the line of the last "array(".I had no idea what was wrong, so I abandoned it and went for the code below, which works perfectly. Thanks –  Naijadeals Sep 8 '12 at 1:20
add comment

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.