-
AuthorPosts
-
December 16, 2020 at 12:10 pm #1267749
Hi, I have a couple of pages where I display custom post types. The post types in the two pages are the same, but they are differentiated by a custom function that works on a acf field (in this case a number corresponding to “year”), showed herebelow:
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; }
What I need is to add the possibility (in front-end) to add a orderby option, similar to the one that is suggested in the back-end blog post (see Enfold documentation)
My need is to enable the possibility of sorting posts by the following parameters: year (= acf field); location (=acf field); post title
I tried to use an external plugin (Search&Filter), but it doesn’t work well as it searches among all posts created (hence also those that are not listed in the page).
Can you suggest me how to solve the problem?
January 4, 2021 at 5:03 am #1270089Hey Elena,
Thank you for the inquiry
This is possible but it will require modifications that are beyond the scope of support. You may need to hire a freelance developer or contact our partner, Codeable.
If you want to implement it yourself, you could look into the following articles for reference.
// https://rudrastyh.com/wordpress/ajax-post-filters.html
// http://techslides.com/sort-wordpress-posts-by-modified-date-using-a-url-paramThe second solution is probably much more simple because the sorting is based on the query or URL parameters, compare to the first solution which requires AJAX and template modifications.
Best regards,
IsmaelJanuary 4, 2021 at 1:21 pm #1270133Thanks Ismael, I will check the two articles you mentioned!
January 5, 2021 at 5:49 am #1270321Hi,
Please let us know if you need additional help, or shall we close this topic?
Best regards,
Jordan ShannonJanuary 7, 2021 at 4:29 pm #1270899Yes please close the topic!
January 8, 2021 at 1:58 pm #1271058 -
AuthorPosts
- The topic ‘How to add an order/orderby option on blog post front-end side’ is closed to new replies.