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 want to display specific posts from an array with specific tags i.e. "Bolivia" and "Brazil" and then show the post thumbnail and permalink.

This is the code I am using so far but as you can see I am not calling the tags.

Thanks.

<?php query_posts(array('category__in' => array(4), 'posts_per_page' => 4)); ?>

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

              <?php $currentid = get_the_id(); ?>

              <div class="list-box">

                <a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($currentid, array(120, 100)); ?></a>

                 <div class="list-box-title"><h3><?php the_title(); ?></h3></div>

               </div>

              <?php
           endwhile;
       endif;

  wp_reset_query();
 ?>
share|improve this question

migrated from stackoverflow.com Apr 18 '12 at 16:04

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 2 down vote accepted

See the WP docs for query_posts.

Relevant excerpt:

The following returns all posts that belong to category 1 and are tagged "apples"

    query_posts( 'cat=1&tag=apples' );

You can search for several tags using +

    query_posts( 'cat=1&tag=apples+apples' );

Or using the array version you're using, something like this:

$args = array(
    'category__in' => array(4),
    'posts_per_page' => 4,
    'tag' => array('Bolivia', 'Brazil')
)
query_posts($args);

String version for your case:

query_posts('category__in=4&posts_per_page=4&tag=Bolivia,Brazil');
share|improve this answer
    
Thanks for your help but I cannot get it to work. I am using this code: <?php $args = array( 'category__in' => array(4), 'posts_per_page' => 4, 'tag' => array('Bolivia', 'Brazil') ) ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="list-box"> <a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($args, array(120, 100)); ?></a> <div class="list-box-title"><h3><?php the_title(); ?></h3></div> </div> <?php endwhile; endif; wp_reset_query(); ?> ?> –  rt840 Apr 15 '12 at 15:36
    
What's the error? Also have you tried the string version? –  HappyTimeGopher Apr 15 '12 at 16:50

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.