//Display All Reviews
function display_all_reviews( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'tag', 'reviews' );
}
}
add_action( 'pre_get_posts', 'display_all_reviews' );
//Movie All Reviews
function display_movie_reviews( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'tag', 'movie-reviews' );
}
}
add_action( 'pre_get_posts', 'display_movie_reviews' );
Display All Reviews is the only thing that is suppose to be displayed on the homepage and display_movie_reviews is suppose to be displayed in the sidebar for its category is_category('movies'), as well as posts in that category. I see they have $query->is_home() but I have tried is_category('movies') without any luck..
Here is the display_movies_reviews markup for the category:
<div id="sidebar-reviews">
<span>Movie Reviews</span>
<ul>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php add_action( 'pre_get_posts', 'display_movie_reviews' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'sidebar-reviews', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'index' ); ?>
<?php endif; ?>
</ul>
</div>
And here is the display_movies_reviews markup for the posts within the movies category:
<!-- ###Movies Single Sidebar### -->
<?php elseif ( ! empty ( $GLOBALS['post'] ) && is_single() && in_category( 'movies', $GLOBALS['post'] ) ) : ?>
<div class="sidebar-ad">
</div>
<div id="sidebar-reviews">
<span>Movie Reviews</span>
<ul>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php add_action( 'pre_get_posts', 'display_movie_reviews' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'sidebar-reviews', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'index' ); ?>
<?php endif; ?>
</ul>
</div>
I have tried fixing it like this:
//Movie All Reviews
function display_movie_reviews( $query ) {
if ( $query->is_category('movies') ) {
$query->set( 'tag', 'movie-reviews' );
}
}
add_action( 'pre_get_posts', 'display_movie_reviews' );
but havent had any luck. Any ideas how I can get the homepage and sidebar working?
edit: sidebar
<?php if ( $query->is_category('movies') ): ?>
<?php $movies = new Wp_Query('tag=movie-reviews'); ?>
<?php while ( $movies->have_posts() ) : ?>
<?php $movies->the_post(); ?>
<?php get_template_part( 'sidebar-reviews', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'index' ); ?>
<?php endif; ?>