-
AuthorSearch Results
-
November 17, 2016 at 4:38 pm #70909
In reply to: Settings & Default / Post (wrong default order)
AnonymousInactivefunction sf_filter_query_args( $query_args, $sfid ) {
if($sfid==1225){
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1225)->current_query();$sf_current_query->get_field_string(“_sfm_event_archives”);
$_sfm_event_archives_array = $sf_current_query->get_array();
$archive_is_check = $_sfm_event_archives_array[_sfm_event_archives][active_terms][0][value];//print_r($archive_is_check);
if($archive_is_check != ‘1’){
$args_custom = array(
“meta_key” => “imic_event_start_dt”,
“orderby” => “meta_value_num”,
“order” => “ASC”,
“meta_query” => Array (
“event_archives” => Array (
“key” => “event_archives”,
“value” => “0”
)
)
);$query_args = array_merge($query_args, $args_custom);
}// si aucun filtre d’appliqué
//if($sf_current_query->is_filtered()!=1){}}
return $query_args;
}
add_filter( ‘sf_edit_query_args’, ‘sf_filter_query_args’, 100, 2 );November 17, 2016 at 4:37 pm #70903In reply to: Settings & Default / Post (wrong default order)
AnonymousInactiveHi,
thanks for your help!!!
It wasn’t the wpml plugin,
but the custom code (that I was sure it wasn’t in cause)
I had to add the bold section here to make it workfunction sf_filter_query_args( $query_args, $sfid ) { if($sfid==1225){ global $searchandfilter; $sf_current_query = $searchandfilter->get(1225)->current_query(); $sf_current_query->get_field_string("_sfm_event_archives"); $_sfm_event_archives_array = $sf_current_query->get_array(); $archive_is_check = $_sfm_event_archives_array[_sfm_event_archives][active_terms][0][value]; //print_r($archive_is_check); if($archive_is_check != '1'){ $args_custom = array( <strong>"meta_key" => "imic_event_start_dt", "orderby" => "meta_value_num", "order" => "ASC",</strong> "meta_query" => Array ( "event_archives" => Array ( "key" => "event_archives", "value" => "0" ) ) ); $query_args = array_merge($query_args, $args_custom); } // si aucun filtre d'appliqué //if($sf_current_query->is_filtered()!=1){} } return $query_args; } add_filter( 'sf_edit_query_args', 'sf_filter_query_args', 100, 2 );
Thanks again for your help guys!
Really nice plugin!November 7, 2016 at 12:21 pm #68984In reply to: Filter input arguments before they get to S&F
AnonymousInactiveThank you Trevor! The issue I was having with
sf_edit_query_args
is that $query_args was empty. I read around in the forum and it turns out I had to use a different priority than the one specified in the docs (like 100) to get results in $query_args using this filter.November 7, 2016 at 12:07 pm #68982In reply to: Filter input arguments before they get to S&F
TrevorParticipantMy guess is that you would need the
sf_edit_query_args
filter:November 4, 2016 at 2:38 pm #68671In reply to: Default result
TrevorParticipantIt IS possible, but I have never done it. You would need to use the is_filtered() function to see if the filter has yet been used (or has been reset) and then use sf_edit_query_args filter to change the incoming filters applied to the page. All this in your child theme functions.php file.
You might find ideas in this github repository from the developer of Search & Filter:
October 29, 2016 at 6:40 pm #67175In reply to: Execute ajax request using javascript?
AnonymousInactiveOne more question.
Is there way to add extra parameter to shortcode?
To set default query.i.e.
[searchandfilter id="1428" show="results" post="123"] function sf_filter_query_args( $query_args, $sfid ) { if($sfid==1428) { /* i'm not sure how to get $shortcode_param */ $query_args['my_post_id'] = $shortcode_param['post']; } return $query_args; } add_filter( 'sf_edit_query_args', 'sf_filter_query_args', 10, 2 );
October 17, 2016 at 6:07 pm #64610In reply to: drop down filter(auto count) not working properly?
AnonymousInactiveI understand.
BTW, Can’t I use these hook to filter dropdown?
sf_edit_query_args or sf_input_object_prehttps://www.designsandcode.com/documentation/search-filter-pro/action-filter-reference/
August 30, 2016 at 2:09 pm #56061Topic: Unable to change post per page
in forum Search & Filter Pro
AnonymousInactiveI’m using S&F on a custom post, but i’m unable to change the amount of posts it show on a page. It seems to be limited to the reading settings of wordpress.
I’m running S&F on a multi-site setup if that helps.
I have tried using pre_get_posts, it works initially but then reverts back to the wp limit once any of the filters are applied, even if you reset.
I’ve also tried the filter ‘sf_edit_query_args’ but that doesn’t play ball either
I will send you site details in my next message
Thank you
July 12, 2016 at 7:31 pm #50954In reply to: Query another WordPress table
AnonymousInactiveHi Trevor,
I used the code bellow in the functions.php file. Shoudn’t I ?
Thank you 🙂function filter_function_name( $query_args, $sfid ) {
//if search form ID = 1272, the do something with this query
if($sfid==1272)
{
//modify $query_args here before returning it
print_r($query_args);
echo “Yeahhhhhhhhhhhh”;
}//return $query_args;
}
add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 10, 2 );April 6, 2016 at 8:48 am #41753In reply to: Load defaults on page load
RossKeymasterHi Christian
I have not yet had chance to implement this feature – as mentioned it only works with archives at the moment – I have just realised though if you are a dev and can do some coding this may already be possible using a filter:
So in there you would manually check to see if the current page/post has a specific category:
https://codex.wordpress.org/Function_Reference/has_category
if(has_category( 'dogs', get_the_ID())) { }
And if so, modify the S&F query to only look inside that category
$query_args['category_name'] = "dogs"
So putting it all together:
function update_search_category( $query_args, $sfid ) { //if search form ID = 225, the do something with this query if($sfid==225) { //here we check to see value is associated with the page if(has_category( 'dogs', get_the_ID())) { $query_args['category_name'] = "dogs" } else if(has_category( 'cats', get_the_ID())) { $query_args['category_name'] = "cats" } else if(has_category( 'snakes', get_the_ID())) { $query_args['category_name'] = "snakes" } } return $query_args; } add_filter( 'sf_edit_query_args', 'update_search_category', 10, 2 );
One big caveat I just realised, you may have to disable ajax – this is because an ajax request gets sent off somewhere else, and I think
has_category
will never give the correct result in an ajax request.Thanks
-
AuthorSearch Results
-
Search Results
-
I’m using S&F on a custom post, but i’m unable to change the amount of posts it show on a page. It seems to be limited to the reading settings of wordpress.
I’m running S&F on a multi-site setup if that helps.
I have tried using pre_get_posts, it works initially but then reverts back to the wp limit once any of the filters are applied, even if you reset.
I’ve also tried the filter ‘sf_edit_query_args’ but that doesn’t play ball either
I will send you site details in my next message
Thank you