Forums › Forums › Search & Filter Pro › Adding custom functions to S&F filtering
Tagged: custom function, Enfold
- This topic has 8 replies, 3 voices, and was last updated 4 years, 11 months ago by
Ross.
-
Trevor(Private) December 16, 2020 at 11:41 am #269961
I think what you want is the filter function that allows you to do the same to our query, which is this:
https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments
Anonymous(Private) December 16, 2020 at 12:12 pm #269971Thanks maybe that the thing, but I am not very expert and I don’t know how to use it.
If I modified the function you suggest and I var_dump the results, I find exactly the list of post I should have, but still the filter doesn’t work
function filter_function_name( $query_args, $sfid ) { //if search form ID = 225, the do something with this query if($sfid==225) { $posts = get_posts($query_args); $today_year = date('yy'); $two_years_ago = $today_year - 2; $current = array(); foreach( $posts as $post ) { $meta = get_post_meta($post->ID); $acf_year = $meta['anno'][0]; if($acf_year < $two_years_ago) { $current[] = $post->ID; } } $query_args = $current; } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );Could you help through it?
Anonymous(Private) December 16, 2020 at 6:31 pm #270052Sorry I already did it, but forgot to change it in the message to you. Still it doesn’t work.
There is an alternative solution, which actually I do not like too much (I tested it on my local website). I display the results in a the custom post type archive page -> that is not affected by the function avia_post_slide_query_mod, thus results are fine. To avoid showing wrong “year” posts I added a specific condition to the S&F form setup under the post meta tab. However this is not a good solution, as the condition should be manually reset every year (there is not a way to automatically define it on the timestamp year). Also, I do not like too much results being displayed in another page.
Hence, I would like to understand how can I force the S&F ajax call on the form taking in consideration that the search and filtering must be done only on displayed posts that are under the condition acf_field year < 2 years from timestamp year
thanks
Ross Moderator(Private) December 21, 2020 at 2:08 pm #270521This reply has been marked as private. -
AuthorPosts