1

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'
        )
    );
}

2 Answers 2

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.

9
  • 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, 2014 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, 2014 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, 2014 at 22:22
  • var_dump after the query is run is empty?
    – Milo
    Apr 16, 2014 at 0:06
  • I tried putting it after the query and in the loop. Nothing was dumped.
    – Wilhelm
    Apr 16, 2014 at 22:58
0

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.

1
  • Thanks but this didn't work. I've updated my code.
    – Wilhelm
    Apr 15, 2014 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.