Forums Forums Search Search Results for 'function sf_edit_query_args'

Viewing 10 results - 101 through 110 (of 123 total)
  • Author
    Search Results
  • #81579

    Anonymous
    Inactive

    Hi Trevor,

    Have you been able to forward this message to the developer yet?

    I have realised there is another method i could try to achieve what i want but this would require to create multiple search forms and then target their IDs individually using the sf_edit_query_args function.

    I understand the developer is a busy man and i don’t want to be a pest but are you able to give an estimated time for when you think he’ll get a chance to look at it?

    This is for a project i’m working on for a client in which the deadline is at the end of the month so if the waiting list is long then i don’t mind going for the alternative method.

    Many thanks

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

    #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

Viewing 10 results - 101 through 110 (of 123 total)