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 have this code in my category.php file

            <?php query_posts( array('post_type'=>'featured' )); 

            $featured = new WP_Query( array('posts_per_page'=>1, 'tax_query'=> array(
            array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => 'fever'
            )
        )));

                while ( $featured->have_posts()) : $featured->the_post();
                unisphere_get_post_image('normal-slider');?>
                <?php endwhile; wp_reset_query(); ?>

This code works, but what I need is where it says 'terms' => 'fever' to instead reference whatever the current category being used in the category.php page would be. I need it to work this way so that my featured image changes out with the current category that being used by the page category.php at that moment.

// Got the answer I needed. Here's a copy of the working code.

            <?php 
            $term = get_queried_object();
            query_posts( array('post_type'=>'featured' )); 

            $featured = new WP_Query( array('posts_per_page'=>1, 'tax_query'=> array(
                array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => $term
                        )
                    ) 
                ));

            while ( $featured->have_posts()) : $featured->the_post();
            unisphere_get_post_image('normal-slider'); ?>
            <?php endwhile; wp_reset_query(); ?>
share|improve this question
    
Just a question...why are you using query_posts when you're also using new WP_Query? –  Brian Fegter Jul 19 '12 at 4:45
    
not sure. just figuring out stuff as I go. –  Jay Flood Jul 19 '12 at 4:48
    
NP :) Here's a great reference post to read through. Very helpful! wordpress.stackexchange.com/questions/1753/… –  Brian Fegter Jul 19 '12 at 4:50
add comment

1 Answer 1

up vote 1 down vote accepted

Try using get_queried_object():

$term = get_queried_object();
echo $term->name;

If you get nothing there, try this:

print_r($wp_query);

Everything you need is in the $wp_query global.

Hope this helps you.

share|improve this answer
    
that did the trick! –  Jay Flood Jul 19 '12 at 4:33
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.