-
AuthorSearch Results
-
January 1, 2017 at 9:35 pm #79470
In reply to: show featured post at top of search results
AnonymousInactiveI’ve started to work on the code by beginning with showing only the featured therapists.
I’ve got the codeadd_filter( 'sf_edit_query_args', 'filter_featured_first', 20, 2 ); function filter_featured_first( $query_args, $sfid ) { if($sfid==491) { $query_args = array('meta_query' => array( 'relation' => 'AND', array('key' => 'featured', 'value' => 1 ) ), 'posts_per_page' => 4 );} return $query_args;}
However, I can’t get the pagination to work. The same posts are being shown on every page.
How do I fix the pagination? And how do I get it to work with the above function edit_posts_orderby()?December 31, 2016 at 8:23 pm #79403In reply to: show featured post at top of search results
AnonymousInactiveThanks so much for your help.
What do you mean by a ‘sort field’? Do you mean in the Search Form UI?
I’m using ‘post meta’ and ‘search’ fields. You can see the filter on http://gethelpisrael.mgtestsite.com/therapist/?_sfm_medical_professional_type=Therapist So would I be ok then?
Also, how would I add the code for the randomisation with the pagination?
Could I leave the filter: add_filter(‘posts_orderby’, ‘edit_posts_orderby’);
and add add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 ); with my custom code and they would both work?
Or do I need to combine them into one function?December 30, 2016 at 7:53 pm #79323In reply to: show featured post at top of search results
RossKeymasterHi Rena
So you want, at the top to show featured therapists (randomised) and then the rest of the results (also randomised, but excluding the the featured therapists)?
This is a little out of scope of the functionality of S&F so you will have to write some custom code but I will give a possible idea on how to implement.
1) Create a custom WP_Query, and find the IDs of all your featured therapists in your site
2) Use our filtersf_edit_query_args
to edit the query of S&F… – more infoYou will find
$query_args['post__in']
will be an array of post IDs… these are actually the IDs from all the results of your search..! so you can re-arrange the array$query_args['post__in']
You would use the IDs from
1)
to see if they are in thepost__in
array, and then move these values to the top of the array.Just make sure the IDs are in the order you want, and put back into
$query_args['post__in']
as an array.Then in S&F as mentioned, choose default (no sorting) in the
post
tab.—
This is an idea of how it could work but would involve writing a lot of custom code depending on your exact requirements – also, it does not take into consideration how to handle the scenario when you are using a
sort
field in your form also.Hope that helps!
Best
December 25, 2016 at 9:24 am #78635In reply to: Old Category Reappears
TrevorParticipantAh, so many questions …
Since this fix was sent to us individually, what happens if there’s a new version of S&F, do I update the plugin then? Will it overwrite the fix that you implemented?
Any fixes done in development versions are rolled into the next (and subsequent) official release, so no worries there.
Should I be worried or cautious for plugin/theme/WP core updates in the future with compatibility with S&F?
Worried? No. As long as you have a current support/updates license, we will continue to support you. any issues that do arise (and inevitably do), do so because the third party theme author/plugin does not follow the protocols laid down in the official WordPress Codex.
Whilst the presence of a theme/plugin on the wordpress.org repositories will tend to indicate that the authors of those plugins/themes have adhered (in the main) to the Codex, many themes and plugins are commercially sold and, as selling is not permitted on wordpress.org, do not always have such a strict adherence to the Codex. This makes our task much harder.
As such, we are in their hands.
Is there a way to show default ticked checkboxes? For example, if on the News page, I just want someone to see a certain category on default when they land on that page?
There are filters that you can use, in S&F Pro, such as the Edit Query Arguments filter. In your child theme functions.php file, you would make a conditional function that checks for the page (name or ID) and checks to see if that field has any settings yet, and if not then you could set it accordingly.
If you search this forum for the key term
sf_edit_query_args
you may find others that have done this, and code snippets might also be in those threads.As to your follow up post. The authors of Avada have indeed changed it and the FAQ detail about Avada (v4) may not be comparable with v5. There are many threads that discuss using Masonry and how to re-trigger it after Ajax has fired. It should be easy to do, but sometimes is not. Other users have achieved it, but I have not seen this myself.
December 14, 2016 at 12:31 pm #76149In reply to: Default option on load
TrevorParticipantYes is the answer, using our sf_edit_query_args filter.
There are many examples of usage also post here on the forum, a key term search for that filter name should yield some.
December 12, 2016 at 3:55 pm #75739In reply to: Exclude category/taxonomy through shortcode
TrevorParticipantSorry, I missed the reference to our documentation:
Where you would do something like:
function filter_function_name( $query_args, $sfid ) { //if search form ID = 225, the do something with this query if($sfid==225) { $query_args['cat__not_in'] = array(235,236,237); // where the 235 etc are the category ID numbers) } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
December 2, 2016 at 11:46 am #73627In reply to: Ignore certain filter from query
AnonymousInactive“put values in each field” means Search&Filter form on frontend?
I thought when form data was submitted, I can catch values in sf_edit_query_args.
But actually I don’t see any values related to filters.i.e. this is a sample of $query_args in sf_edit_query_args
At that time I correct this data, couple of filters had values.(selected)
But there isn’t any in $query_args.
Array
(
[paged] => 1
[search_filter_id] => 194
[search_filter_override] =>
[posts_per_page] => 10
[post_status] => Array
(
[0] => publish
)[meta_query] => Array
(
)[post_type] => product_resource
)December 1, 2016 at 1:04 am #73392In reply to: Ignore certain filter from query
AnonymousInactiveI don’t see the filter value in first parameter of sf_edit_query_args.
Where do I modify it?November 30, 2016 at 4:37 pm #73269In reply to: filter authors on results
RossKeymasterHi Laura
I see potentially a few areas where something may be going wrong.
1)
pre_get_posts
is an action, however oursf_edit_query_args
is a filter, and you are trying to combine the two2) Our docs mention you should not use pre_get_posts and use our own filter instead.. Therefor, you must use our filter as per the docs:
add_filter( 'sf_edit_query_args', 'filter_hide', 20, 2 );
3) Your second code snippet should be close to working once you get it setup with our filter rather than pre_get_posts, however, I see another line where I’m not sure the logic is correct, I see you are trying to set
author__not_in
.. I’ve not used this before but assume it for excluding authors? If its likepost__not_in
then it will take an array of IDs..I see you are using
$meta = get_user_meta(get_current_user_id(), 'hide', true);
to get teh values for this field – what does this get? It doesn’t look like it gets the Author IDs that you want to exclude from your search? Why not try as a test excluding some author IDs that are known to you, so this should really be:
$meta = array(1, 22);
If the authors you wanted to exclude had the IDs of1
and22
4) Then finally, you are setting your exclude authors into the variable
$args
but then you return a different variable,$query_args
, so your changes are not being used at all or passed back to S&F…I’ve rewritten your code (untested) in to how it should look:
function filter_hide( $query_args, $sfid ) { //$meta = get_user_meta(get_current_user_id(), 'hide', true); //if search form ID = 2259, then hide authors' posts if($sfid==2259) { //these are the Author IDs you want to exclude $query_args['author__not_in'] = array(1, 10); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_hide', 50, 2 );
If you wanted to hide only the current users posts you would change 1 line above to something like:
$query_args['author__not_in'] = array(get_current_user_id());
Hope that helps
November 29, 2016 at 8:13 pm #72977In reply to: input field for post meta value search?
AnonymousInactiveActually what I want is not that user select range of value and search single custom field.
I want to have user input single number and search two custom fields see if number is in range of two.I tried this in sf_edit_query_args to catch search form value and set it to custom fields.
$zip=$query_args['s']; unset($query_args['s']); $query_args['meta_query']=Array(Array('key'=>'zip_min','value'=>$zip,'compare'=>'<=','type'=>'NUMERIC,'),Array('key'=>'zip_max','value'=>$zip,'compare'=>'>=','type'=>'NUMERIC,'));
So far it seems to to working but I’m not sure this is proper way.
-
AuthorSearch Results