title: Wordpress Notice: Trying to get property of non-object
body: <p>I have a custom post type set up on my blog and a special page for the taxonomy.  On the taxonomy page I am getting the below error. Can anyone give me some tips on how to resolve this error?</p>
  
  <p>The page loads fine and works as I would expect.  But I get the below error if I have debug set to true.  I would like to resolve this.  I pasted the cost from the loop which is run two time on the page with different criteria.</p>
  
  <pre><code>Notice: Trying to get property of non-object in /home3/ans/public_html/wp-includes/post-template.php on line 29
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php
  query_single('dealers', 'publish', '1', $taxtype, $value);
   ?&gt;
  
   &lt;?php if (have_posts()) : ?&gt;
   &lt;?php while (have_posts()) : the_post(); ?&gt;
  
   &lt;?php 
     $address=get_post_meta($post-&gt;ID, 'wpcf-street_address', TRUE); 
     $city=get_post_meta($post-&gt;ID, 'wpcf-city', TRUE); 
     $state=get_post_meta($post-&gt;ID, 'wpcf-state_abbreviation', TRUE); 
     $zip=get_post_meta($post-&gt;ID, 'wpcf-zip_code', TRUE); 
     $phone=get_post_meta($post-&gt;ID, 'wpcf-phone_number', TRUE); 
     $paid=get_post_meta($post-&gt;ID, 'wpcf-paid', TRUE);
     $post_id=get_the_ID();
     get_each_dealer_brand($post_id);?&gt;
  
    &lt;?php 
    echo "&lt;ul class=\"ullisting\"&gt;";
    if($paid==1)
    {
     echo "&lt;li&gt;&lt;p class=\"plisting\"&gt;&lt;strong&gt;&lt;a href=\"";the_permalink(); echo  "\"&gt;";the_title();echo "&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;";
      echo "&lt;li&gt;&lt;p class=\"plisting\"&gt;$address | $city, $state $zip&lt;/p&gt;&lt;/li&gt;";
  echo "&lt;li&gt;&lt;p class=\"plisting\"&gt;P: $phone&lt;/p&gt;&lt;/li&gt;";
      echo "&lt;li&gt;&lt;p class=\"listing\"&gt;&lt;span&gt;&lt;small&gt;$brands_list&lt;/small&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;";
   }
  echo "&lt;/ul&gt;";
  ?&gt;
  
   &lt;?php endwhile; ?&gt;
  
   &lt;?php
   wp_reset_query(); 
   wp_reset_postdata(); 
   unset($brands_list);
   ?&gt;
  </code></pre>
  
  <p>This is the function referenced above:</p>
  
  <pre><code>   function query_single($posttype, $poststatus, $paidvalue, $taxtype, $value) {
  
       global $wp_query;
      $wp_query = new WP_Query();
    $args = array(
     'post_type' =&gt; $posttype,
     'post_status' =&gt; array($poststatus),
     'orderby' =&gt; 'rand', 
     'posts_per_page' =&gt; 20,
     'meta_query' =&gt; array(
         array(
             'key' =&gt; 'wpcf-paid',
             'value' =&gt; array($paidvalue),
             'compare' =&gt; 'IN',
         )
     ),
      'tax_query' =&gt; array(
              array(
                  'taxonomy' =&gt; $taxtype,
                  'field' =&gt; 'slug',
                  'terms' =&gt; $value
              )
          )
      );
     return $wp_query-&gt;query($args);
     }
  </code></pre>