Support

Account

Home Forums Front-end Issues get_field_object return false Reply To: get_field_object return false

  • Thanks a lot John for the reply.
    I saved the value in a global array on my functions.php (or at least I think so..)

    Any clue why on the archive-cars.php is working and in the category.php isn’t?

    Here my functions.php file

    **
     * Archive cars FILTER using pre get post?
     */
    
     // array of filters
     //NOTE: it's a sub field inside a field group so the meta query becomes => groupname_subfield
    	$GLOBALS['my_query_filters'] = array(
    	 'car_info_petrol'	=> 'carburante',
    	 'car_info_gearshift'	=> 'cambio',
    	 'car_info_brand'	=> 'marca'
    	);
    
     function my_pre_get_posts( $query ) {
    
     	// do not modify queries in the admin
     	if( is_admin() ) {return $query;}
    
     	// only modify queries for 'cars' post type
     	if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'cars' ) {
    
    		// loop over filters
    		foreach( $GLOBALS['my_query_filters'] as $key => $name ) {
    
    			//allow the url to alter the query
    	 		if( isset($_GET[$name]) ) {
    
    				$meta_query[] = array(
    					'key' => $key,
    					'value' => $_GET[$name],
    					'compare' => 'IN'
    				);
    
    				//Update the meta query args
    				$query->set('meta_query', $meta_query);
    
    	     }
    		}
    
     	} //End of the if only on the post type cars
    
     	// return
     	return $query;
    
     }
    
     add_action('pre_get_posts', 'my_pre_get_posts');