Search Results for 'function sf_edit_query_args'

Forums › Forums › Search › Search Results for 'function sf_edit_query_args'

Viewing 10 results – 121 through 130 (of 141 total)
  • Author
    Search Results
  • #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.

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

    #70909

    Anonymous
    Inactive

    function 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 );

    #70903

    Anonymous
    Inactive

    Hi,
    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 work

    
    function 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!

    #68671

    In reply to: Default result


    Trevor
    Participant

    It 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:

    https://github.com/rmorse

    #67175

    Anonymous
    Inactive

    One 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 );
    #50954

    Anonymous
    Inactive

    Hi 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 );

    #41753

    Ross
    Keymaster

    Hi 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:

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

    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

Viewing 10 results – 121 through 130 (of 141 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.