Forums › Forums › Search & Filter Pro › Order blog posts in Enfold
Tagged: sort by acf
- This topic has 3 replies, 2 voices, and was last updated 4 years, 8 months ago by
Trevor.
-
Anonymous(Private) October 29, 2020 at 11:58 am #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(Private) October 29, 2020 at 6:07 pm #264616You 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).
-
AuthorPosts