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'm attempting to display posts from a 'Uncategorized' category under a custom taxonomy called 'Reviews' but without much luck.

I'm using get_template_part('loop','review') to call loop-review.php which contains my taxonomy loop but for some reason, nothing will show up. What gives?

Here are the contents of loop-review.php...

<div class="row no-margin detail">
    <p class="title"><span>reviews</span></p>
    <?php 

    $args = array(
        'post_type' => 'post',
        'tax_query' => array(
            array(
                'taxonomy'  => 'review',
                'field'     => 'slug',
                'terms'     => 'uncategorized'
            )
        )
    ); $review_query = new WP_Query($args); ?>
    <?php if ($review_query->have_posts()): ?>
            <?php while ($review_query->have_posts()): $review_query->the_post(); ?>
                    <p class="quote">
                            <?php the_content(); ?>
                            <span><?php the_title(); ?></span>
                    </p>
            <?php endwhile; ?>
            <!-- end of the loop -->
                    <?php wp_reset_postdata(); ?>
    <?php else:  ?>
                    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
</div>

I call get_template_part('loop','review') inside my my category.php...

<?php 

get_header(); 

if (is_category('portfolio')): 
    get_template_part('single','portfolio'); 
    get_template_part('loop','review');
else: 
    get_template_part("single","blog");
endif; 

get_footer(); 

?>

Lastly, here is the code from my functions.php...

add_action('init', 'build_taxonomies', 0);
function build_taxonomies(){
        register_taxonomy('review', 'post', array(
            'hierarchical'    => 'true',
            'label'           => 'Reviews',
            'query_var'       => 'true',
            'rewrite'         => 'true'
        )
    );
}
share|improve this question
add comment

2 Answers 2

There are no methods the_content() or the_title() of your query object.

These:

$review_query->the_content();
$review_query->the_title();

should just be

the_content();
the_title();

If you had debugging enabled you would see an error informing you of this.

share|improve this answer
    
Thanks but still no posts. I've updated my code to reflect your feedback. Also, I've enabled debugging and am not receiving any errors? –  Wilhelm Apr 15 at 13:23
    
are you sure there are posts that match the query? var_dump($review_query); and inspect the query parameters, make sure there isn't a filter of some sort altering the query. –  Milo Apr 15 at 17:30
    
I've tried that already. I have two posts in 'Uncategorized' category in 'Review' but var_dump returns nothing. –  Wilhelm Apr 15 at 22:22
    
var_dump after the query is run is empty? –  Milo Apr 16 at 0:06
    
I tried putting it after the query and in the loop. Nothing was dumped. –  Wilhelm Apr 16 at 22:58
show 4 more comments

At first glance, I see that your query is calling for 'post_type' => 'page' while the taxonomy is registered on the post object type. Changing the post type to post ('post_type' => 'post') should fix the problem.

share|improve this answer
    
Thanks but this didn't work. I've updated my code. –  Wilhelm Apr 15 at 3:28
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.