• In my sidebar, I’m getting the above error when it’s displayed on a page that doesn’t have post content (such as 404, tag pages, etc.).

    I’m aware that I am querying the post ID (even if there isn’t one due to the nature of the page) in order to remove the current post from the generated list, but I’m using “WP_Query” which is supposed to be used outside the loop. Unless I am missing something?

    The error is in line 7 apparently… Any feedback welcome!

    BONUS Question: Is my rewind_posts necessary between the two loops?

    —————————–

    <div class="sidebar">
    			<div class="sidebarCard">
    						<h2><a href="/reviews/">Music Reviews</a></h2>
    
    							<div class="sideContent" id="reviews">
    							<ul>
    							<?php	$args_reviews = array('posts_per_page' => 4,'category_name' => 'Albums, EPs','post__not_in' => array( $post->ID ),	'orderby' => 'date', 'order' => 'DESC');
    							$the_query = new WP_Query( $args_reviews );
    							while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    								<li><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail( array(150,150) ); ?></a></li>
    
    							<?php endwhile; ?>
    							</ul>
    							</div>
    			</div>
    
    <?php rewind_posts(); ?>
    
    			<div class="sidebarCard" id="subscribeBox">
    						<h2><a href="http://eepurl.com/sLjsP">Subscribe</a></h2>
    							<!-- Begin MailChimp Signup Form -->
    							<!--End mc_embed_signup-->
    			</div>
    
    			<div class="sidebarCard">
    						<h2><a href="/tutorials/">Music Tutorials</a></h2>
    
    							<div class="sideContent">
    							<?php $args_tutorials = array('posts_per_page' => 2, 'category_name' => 'tutorials','post__not_in' => array( $post->ID ),	'orderby' => 'date', 'order' => 'DESC');
    							$the_query = new WP_Query( $args_tutorials );
    							while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    									<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(array(300,300)); ?></a>
    
    									<div class="textStrip">
    									<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?> </a>
    									</div>
    
    							<?php endwhile; ?>
    							</div>
    			</div>
    
    			<div class="sidebarCard">
    					<h2>Advertisement</h2>
    							<div>
    							<!--Ad Box-->
    							</div>
    			</div>
    
    </div>
  • The topic ‘Notice: Trying to get property of non-object [Only on non post pages]’ is closed to new replies.