Title: get_queried_object() throwing errors
Last modified: August 21, 2016

---

# get_queried_object() throwing errors

 *  [gamelust](https://wordpress.org/support/users/gamelust/)
 * (@gamelust)
 * [12 years ago](https://wordpress.org/support/topic/get_queried_object-throwing-errors/)
 * Hello, I was using your plugin for a website using the post 2 post plugin and
   noticed that it was throwing errors at a rather high rate.
 * The error I was receiving was **Undefined property: WP_Query::$post …. line 3700**
   and it was being thrown by these 3 lines.
 *     ```
       add_filter('posts_join', array(&$this, 'reOrder_query_join'));
       add_filter('posts_where', array(&$this, 'reOrder_query_where'));
       add_filter('posts_orderby', array(&$this, 'reOrder_query_orderby'));
       ```
   
 * The wp_query errors were always followed up by anywhere from 10-30 undefined 
   object/variable errors from lines 74, 75, 83, 97, 98, 106, 121, 122, and 130.
 * What worked for me was changing these 3 functions by adding a check for is_category()
 * this is the added line
 * if($wp_query->is_category()){ …. }
 * here is the full function with the conditional check
 *     ```
       public function reOrder_query_join($args){
       	    global $wpdb,$wp_query;
   
       	    $table_name = $wpdb->prefix . $this->deefuse_ReOrder_tableName;
   
       	    if($wp_query->is_category()){
       			$queriedObj = $wp_query->get_queried_object();
   
       		    $category_id = $queriedObj->slug;
       		    $theID = $queriedObj->term_id;
   
       		    if(!$category_id) {
       				$category_id = $this->custom_cat;
       		    }
   
       		    $userOrderOptionSetting = $this->getOrderedCategoriesOptions();
       		    if($userOrderOptionSetting[$theID] == "true" && $this->stop_join == false){
       				$args .= " INNER JOIN $table_name ON ".$wpdb->posts.".ID = ".$table_name.".post_id and incl = 1  ";
       				//echo $args;
       			}
       		}
   
       	    return $args;
       	}
       ```
   
 * Right now this fix is working for me, hopefully this will help in the future.
 * [https://wordpress.org/plugins/reorder-post-within-categories/](https://wordpress.org/plugins/reorder-post-within-categories/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [dochara](https://wordpress.org/support/users/dochara/)
 * (@dochara)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/get_queried_object-throwing-errors/#post-4955658)
 * Thank you, saved me a ton of hair and time.
 *  [ditler](https://wordpress.org/support/users/ditler/)
 * (@ditler)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/get_queried_object-throwing-errors/#post-4955666)
 * Thank you! This should be incorporated into an update

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘get_queried_object() throwing errors’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/reorder-post-within-categories_c18d38.
   svg)
 * [ReOrder Posts within Categories](https://wordpress.org/plugins/reorder-post-within-categories/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/reorder-post-within-categories/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/reorder-post-within-categories/)
 * [Active Topics](https://wordpress.org/support/plugin/reorder-post-within-categories/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/reorder-post-within-categories/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/reorder-post-within-categories/reviews/)

 * 2 replies
 * 3 participants
 * Last reply from: [ditler](https://wordpress.org/support/users/ditler/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/get_queried_object-throwing-errors/#post-4955666)
 * Status: not resolved