-
AuthorSearch Results
-
June 2, 2020 at 3:05 pm #246975
AnonymousInactiveI used this just to accomplish the first step:
function mk_purchased_filter_function( $query_args, $sfid ) {
//if search form ID = 225, the do something with this query
if($sfid==62057)
{//modify $query_args here before returning it
$include = array(154400,148684);
$query_args[‘post__in’] = $include;
}return $query_args;
}
add_filter( ‘sf_edit_query_args’, ‘mk_purchased_filter_function’, 20, 2 );____________________
BUT: It does not influence my results. Maybe because Relevanssi is used for the filter, too?
Or is there any other explanation?[searchandfilter id=”62057″]
[searchandfilter slug=”woocommerce-shop”]May 6, 2020 at 4:35 pm #242872In reply to: A third sort order?
AnonymousInactiveNevermind. I didn’t realize I had to also manually add the meta_query to get the search order to work. Here is my working code:
function filter_function_name( $query_args, $sfid ) { //if search form ID = 225, the do something with this query if($sfid==23142) { $query_args["meta_query"] = array( 'relation' => 'AND', 'subject_code' => array( 'key' => 'subject_code', 'compare' => 'EXISTS', ), 'course_number' => array( 'key' => 'course_number', 'compare' => 'EXISTS', ), 'start_date' => array( 'key' => 'start_date', 'compare' => 'EXISTS', ), ); $query_args["orderby"] = array( 'subject_code' => 'asc', 'course_number' => 'asc', 'start_date' => 'asc', ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );Please feel free to close this ticket. Thank you!
May 6, 2020 at 4:07 pm #242855In reply to: A third sort order?
AnonymousInactiveThank you. I restored the Posts settings to the default order and used the following code, which is not affecting the sort order:
function filter_function_name( $query_args, $sfid ) { if($sfid==23142) { $query_args["orderby"] = array( 'subject_code' => 'asc', 'course_number' => 'asc', 'start_date' => 'asc', ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );It works if I set just a single order like so:
function filter_function_name( $query_args, $sfid ) { if($sfid==23142) { $query_args["orderby"] = 'subject_code'; } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );Do I need to format the $query_args differently? That’s how I do it in a regular WP_Query…
Thank you!
April 30, 2020 at 5:43 pm #242232Topic: Relation OR in filter
in forum Search & Filter Pro
AnonymousInactiveHi there,
we would like to add a reltion OR about two field.
We can’t set it in admin panel so we try to integrate it by php.
In function.php we add this:function filter_results( $query_args, $sfid ) { if($sfid==3981) { $query_args = array( "meta_query" => array( 'relation' => 'OR', array( 'key' => 'immobile_disponibile', 'compare' => 'NOT EXISTS', ), array( 'key' => 'immobile_disponibile', 'value' => '1', 'compare' => 'NOT LIKE', ), ), "meta_key" => "immobile_disponibile", 'orderby' => 'menu_order', "order" => "ASC", ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_results', 20, 2 );But… not work.
April 30, 2020 at 11:18 am #242101
RossKeymasterNo not really – we don’t have much in terms of devs accessing our functions to do DB queries etc our way – so so the sf_edit_query_args is usually the way to go.
If your meta query requires a meta key to be an exact value, I can provide some code to set this in the query which should be much faster – its a bit clunky (we hope to improve this) but it taps in to our tables for a performance boost.
Let me know what you’re trying to do (share the snippet of code if you like)
Thanks
April 29, 2020 at 3:31 pm #242002In reply to: Searching based on multiple CPT
RossKeymasterHi Keith
The filter is
sf_apply_filter_sort_post__in$post__in = apply_filters('sf_apply_filter_sort_post__in', $this->query_args['post__in'], $this->query_args, $this->sfid);Which takes an array of post IDs (the results S&F has found) and must return those posts.
You’ll then have to disable sorting and sort by
post__inin the query (actually, you might be able to leave this set as “default” ordreing in your search form options), you can use thesf_edit_query_argsfilter to do this.If you’re going to follow the link above exactly, the
JOINoption might work for you anyway, but there’s two potential approaches for you to try.Thanks
April 6, 2020 at 3:10 pm #239148In reply to: Use single date input as lower bound for date meta
AnonymousInactiveHow would I go about adding the To-date into the query? This is the query args that I get when I add the sf_edit_query_args filter (even with dates put in):
Array ( [paged] => 1 [search_filter_id] => 144 [search_filter_override] => [posts_per_page] => 10 [post_status] => Array ( [0] => publish ) [meta_query] => Array ( ) [post_type] => cursus [post__in] => Array ( [0] => 0 ) )I can’t see any of the form inputs here, the only thing that seems to change is when I put in a search word, the [s]-arg is added.
April 2, 2020 at 2:34 pm #238762
AnonymousInactiveI’m trying to figure out whether it’s possible to use a single date input as a lower bound for posts containing a ‘start date’ meta, so that if I input for example 2020-04-15 it will return me all posts having a start date of that AND later in the future. Right now it only returns posts having exactly that start date.
If I add a filter to sf_edit_query_args, I can’t see the date or any meta query arguments entered in the search form, same goes for the sf_main_query_pre_get_posts filter. Is it possible to hook in anywhere to change the meta_compare type of the query for the start date meta key?
March 20, 2020 at 1:07 pm #237362
RossKeymasterHi Sigurd
After scratching my head I managed to figure out the issue.
We perform our search outside of the regular
WP_Query, so if you choose a category in our search form, WP doesn’t actually “know” its restrciting to a specific category, because our search does that, so WP appends the stick post…I’ve managed to come up with some code, that add the WP category to the
WP_Query(even though our plugin has already restricted the posts to this category), but now WP also knows that at a category restriction is happening, and excludes the sticky:add_filter("sf_edit_query_args", "add_wp_category_to_query", 100, 2); function add_wp_category_to_query($query_args, $sfid){ //if($sfid == 1234){ //you can restrict this behaviour to a search form ID //get user category selection from the search form (ie, detect which categories have been selected) global $searchandfilter; $query_data = $searchandfilter->get($sfid)->current_query(); $query_data_array = $query_data->get_array(); if(isset($query_data_array['_sft_category'])){ $category_values = $query_data_array['_sft_category']['active_terms']; $current_category_ids = array(); //this will contain all the IDs of the categories that have been selected in the search form foreach($category_values as $category){ array_push($current_category_ids, $category['id']); } //restrict query to WP category $query_args['category__in'] = $current_category_ids; } //} return $query_args; }As there may be some small overhead when implementing this code, you can uncomment the first
if(line, and restrict this to a specific search form / query.I hope that makes sense & works!
Best
March 19, 2020 at 9:28 pm #237281Topic: Show posts with no meta
in forum Search & Filter Pro
AnonymousInactiveHi,
I created a form that includes post meta fields. I would like it to also include posts that do not have these meta keys at all.
It is especially a problem because one might use other fields to filter the results, but once the form is submitted the meta fields (range sliders in that case) are taken into account as well, and posts with no meta disappear.
I tried to use the “sf_edit_query_args” filter, but it seems the meta_query is empty when it is applied…
maybe I am using it wrong?Thank you very much!
-
AuthorSearch Results
Search Results for 'sf_edit_query_args'
-
Search Results
-
Topic: Relation OR in filter
Topic: Show posts with no meta
Hi,
I created a form that includes post meta fields. I would like it to also include posts that do not have these meta keys at all.
It is especially a problem because one might use other fields to filter the results, but once the form is submitted the meta fields (range sliders in that case) are taken into account as well, and posts with no meta disappear.
I tried to use the “sf_edit_query_args” filter, but it seems the meta_query is empty when it is applied…
maybe I am using it wrong?Thank you very much!