Forums Forums Search Search Results for 'sf_edit_query_args'

Viewing 10 results - 141 through 150 (of 175 total)
  • Author
    Search Results
  • #79470

    Anonymous
    Inactive

    I’ve started to work on the code by beginning with showing only the featured therapists.
    I’ve got the code

    add_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()?

    #79403

    Anonymous
    Inactive

    Thanks 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?

    #79323

    Ross
    Keymaster

    Hi 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 filter sf_edit_query_args to edit the query of S&F… – more info

    You 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 the post__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

    #78635

    In reply to: Old Category Reappears


    Trevor
    Participant

    Ah, 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.

    #76149

    In reply to: Default option on load


    Trevor
    Participant

    Yes 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.

    #75739

    Trevor
    Participant

    Sorry, I missed the reference to our documentation:

    https://www.designsandcode.com/documentation/search-filter-pro/action-filter-reference/#Edit_Query_Arguments

    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 );
    #73627

    Anonymous
    Inactive

    “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
    )

    #73392

    Anonymous
    Inactive

    I don’t see the filter value in first parameter of sf_edit_query_args.
    Where do I modify it?

    #73269

    Ross
    Keymaster

    Hi Laura

    I see potentially a few areas where something may be going wrong.

    1) pre_get_posts is an action, however our sf_edit_query_args is a filter, and you are trying to combine the two

    2) 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 like post__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 of 1 and 22

    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

    #72977

    Anonymous
    Inactive

    Actually 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.

Viewing 10 results - 141 through 150 (of 175 total)