• I’m stuck on this code. I’m trying to modify the loop on ‘Historias’ archives ( post type ) to display only pets with pet_owner_id from the current user logged-in

    I’ve tried putting this code on my plugin, but it’s doesn’t work, dumping ‘$query’ displays meta_query as false

    [“meta_query”]=>
    bool(false)

    add_filter('parse_query', 'mr_query_filter_by_petowner');
    
    function mr_query_filter_by_petowner(  $query  )
    {
    	global $pagenow, $post_type;
    
           if (!is_admin() && is_archive() && ('historias' == $post_type) )
    	   {
    
    			if(function_exists('set_query_var')){
    				set_query_var( 'meta_query', array( array( 'key' => 'pet_owner_id', 'value' => '1' ) ) );
    			}else{
    				$query->set( 'meta_key', 'pet_owner_id' );
    				$query->set( 'meta_value', '1' );
    			}
    			return $query;
    			//var_dump($query);
           }
    }

    but when I do this on my archive-historias.php file before the ‘Loop’

    $a = array(
    							'meta_query' => array(
    													array(
    														'key' => 'pet_owner_id',
    														'value' => '2',
    														'compare' => '='
    													)
    												)
    						);
    		global $wp_query;
    		$args = array_merge( $wp_query->query, $a );
    
    		query_posts($args );

    it works fine, what is wrong with my code? any bug or it’s me?
    I don’t want to break my code on my template to keep everything clean

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘set_query_var on parse_query is not setting custom values’ is closed to new replies.