Forums Forums Search & Filter Pro Order blog posts in Enfold

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Anonymous
    #264547

    Hi I have a page made with Avia Layout Builder blog posts element. It shows a custom post type containing acf fields (year = anno and location = luogo)

    The posts are pre-filtered with this function (registered in functions.php)

    add_filter('avia_post_slide_query', 'avia_post_slide_query_mod',10, 2);
    function avia_post_slide_query_mod($query, $params) {
    	$posts = get_posts($query);
    	$today_year = date('yy');
    	$two_years_ago = $today_year - 2;
    	$current = array();
    
    		foreach( $posts as $post ) {
    			$meta = get_post_meta($post->ID);
    			
    			
    			if (is_page(112)){
    				$acf_year = $meta['anno'][0];
    				if($acf_year >= $two_years_ago & $acf_year <= $today_year) {
    				$current[] = $post->ID;
    				}	
    			}
    			else if (is_page(204))	{
    				$acf_year = $meta['anno'][0];
    				if($acf_year < $two_years_ago) {
    				$current[] = $post->ID;
    				}	
    			}
    			else if (is_archive()) {
    				return $query;
    			}
    		}
    
    	$query['post__in'] = $current;
    
    	return $query;
    }

    I created a search&filter widget on the left of the blog posts container, where I just need the order function. By clicking on specific values (cpt title, meta key “year” and meta key “location”) I want them ordered desc or asc. However it doesn’t work.

    Can you help me please? I can give you access to the page online

    Trevor
    #264616

    You would need to apply the ordering either in the Posts tab of the form, or using this filter:

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    Our plugin will override settings made in the normal wp_query, including post__in (some settings you cannot set with this filter function, such as post__in).

    Anonymous
    #264698
    This reply has been marked as private.
    Trevor
    #264797

    Can you share with me the function you wrote using our filter? I can then ask our developer, Ross, if he can take a look.

Viewing 4 posts - 1 through 4 (of 4 total)