Search Results for 'function sf_edit_query_args'

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

Viewing 10 results – 41 through 50 (of 141 total)
  • Author
    Search Results
  • #217825

    Anonymous
    Inactive

    I am using the same filter to modify the main shop search too. This one works fine:

    
    function update_search_category( $query_args, $sfid ) {
    
      $query_args['tax_query'] = array(
        array(
          'taxonomy'      => 'product_cat',
          'terms'         => '20',
          'operator'      => 'IN',
        ),
      );
    
      return $query_args;
    
    }
    add_filter( 'sf_edit_query_args', __NAMESPACE__.'\\update_search_category', 20, 2 );
    
    #217706

    Anonymous
    Inactive

    Yes it is a function, I was just showing you only the parts which you needed to see, here is it all:

    
    /**
     * USER PROFILE - Modify search form args
     */
    function user_liked_products_search_filter( $query_args, $sfid ) {
    
      if ( $sfid == 26 ) {
        $query_args = array (
          'meta_query' => array(
            array(
              'key'       => '_likes',
              'value'     => 1,
            ),
          ),
        );
      }
    
      return $query_args;
    
    }
    add_filter( 'sf_edit_query_args', __NAMESPACE__.'\\user_liked_products_search_filter', 100, 2 );
    
    #217681

    Anonymous
    Inactive

    I have checked every similar thread regarding this but am still stuck it seems:

    I’m trying to filter the products on my S&F form to display only those products with a certain number of ‘LIKES’.

    
      if ( $sfid == 26 ) {
        $query_args = array (
          'meta_query' => array(
            array(
              'key'       => '_likes',
              'value'     => 1,
            ),
          ),
    	  );
      }
    
      return $query_args;
    
    }
    add_filter( 'sf_edit_query_args', __NAMESPACE__.'\\user_liked_products_search_filter', 100, 2 );
    

    The function itself is running and also definitely against form ID 26. However it doesn’t appear in the S&F query it seems, here is a dump of the following:

    
     global $searchandfilter;
     $sf_current_query = $searchandfilter->get(26)->current_query();
     var_dump($sf_current_query);
    
    
    object(Search_Filter_Active_Query)[2753]
      public 'sfid' => int 26
      private 'is_set' => boolean true
      private 'query_array' => 
        array (size=0)
          empty
      private 'form_fields' => 
        array (size=2)
          'search' => 
            array (size=4)
              'type' => string 'search' (length=6)
              'heading' => string '' (length=0)
              'placeholder' => string 'Search …' (length=10)
              'accessibility_label' => string '' (length=0)
          '_sft_product_cat' => 
            array (size=18)
              'type' => string 'taxonomy' (length=8)
              'input_type' => string 'select' (length=6)
              'heading' => string '' (length=0)
              'accessibility_label' => string '' (length=0)
              'all_items_label' => string '' (length=0)
              'show_count' => int 1
              'hide_empty' => int 1
              'hierarchical' => int 1
              'include_children' => int 0
              'drill_down' => int 0
              'sync_include_exclude' => int 1
              'combo_box' => int 1
              'no_results_message' => string '' (length=0)
              'operator' => string 'and' (length=3)
              'order_by' => string 'default' (length=7)
              'order_dir' => string 'asc' (length=3)
              'exclude_ids' => string '' (length=0)
              'taxonomy_name' => string 'product_cat' (length=11)
      private 'query_str' => int -1
      public 'plugin_slug' => string 'search-filter' (length=13)
      public 'form_settings' => 
        array (size=37)
          'use_template_manual_toggle' => int 1
          'enable_taxonomy_archives' => int 0
          'enable_auto_count' => int 0
          'auto_count_refresh_mode' => int 1
          'auto_count_deselect_emtpy' => int 0
          'template_name_manual' => string 'search.php' (length=10)
          'page_slug' => string '' (length=0)
          'post_types' => 
            array (size=1)
              'product' => int 1
          'post_status' => 
            array (size=1)
              'publish' => int 1
          'use_ajax_toggle' => int 1
          'scroll_to_pos' => string '0' (length=1)
          'pagination_type' => string 'normal' (length=6)
          'custom_scroll_to' => string '' (length=0)
          'auto_submit' => int 1
          'display_results_as' => string 'shortcode' (length=9)
          'update_ajax_url' => int 1
          'only_results_ajax' => int 1
          'ajax_target' => string '#main' (length=5)
          'ajax_links_selector' => string '.pagination a' (length=13)
          'infinite_scroll_container' => string '' (length=0)
          'infinite_scroll_trigger' => string '-100' (length=4)
          'infinite_scroll_result_class' => string '' (length=0)
          'show_infinite_scroll_loader' => int 1
          'results_per_page' => int 10
          'exclude_post_ids' => string '' (length=0)
          'field_relation' => string 'or' (length=2)
          'default_sort_by' => string '0' (length=1)
          'sticky_posts' => string '' (length=0)
          'default_sort_dir' => string 'desc' (length=4)
          'default_meta_key' => string '_um_core' (length=8)
          'default_sort_type' => string 'numeric' (length=7)
          'secondary_sort_by' => string '0' (length=1)
          'secondary_sort_dir' => string 'desc' (length=4)
          'secondary_meta_key' => string '_um_core' (length=8)
          'secondary_sort_type' => string 'numeric' (length=7)
          'taxonomies_settings' => 
            array (size=11)
              'category' => 
                array (size=2)
                  ...
              'post_tag' => 
                array (size=2)
                  ...
              'post_format' => 
                array (size=2)
                  ...
              'action-group' => 
                array (size=2)
                  ...
              'um_hashtag' => 
                array (size=2)
                  ...
              'product_type' => 
                array (size=2)
                  ...
              'product_visibility' => 
                array (size=2)
                  ...
              'product_cat' => 
                array (size=2)
                  ...
              'product_tag' => 
                array (size=2)
                  ...
              'product_shipping_class' => 
                array (size=2)
                  ...
              'ep_custom_result' => 
                array (size=2)
                  ...
          'results_url' => string 'https://dev.influxshopping.co.uk/user/admin/?profiletab=products' (length=64)
      public 'cache_table_name' => string 'wp_search_filter_cache' (length=22)
      public 'term_results_table_name' => string 'wp_search_filter_term_results' (length=29)
      public 'field_values' => 
        array (size=0)
          empty
    

    No sign of the _likes field in the query at all.

    #215143

    Trevor
    Participant

    I think you will need to use this filter (the code goes in to your child theme functions.php file):

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    Like this:

    function exclude_password_protected_posts( $query_args, $sfid ) {
    	if($sfid==225)
    	{
    		$query_args['has_password'] = FALSE;
    	}
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'exclude_password_protected_posts', 20, 2 );

    where you need to change the ID number (in the example it is 225, so use the ID number of your form).

    #213628

    Anonymous
    Inactive

    TJ, another quick example maybe to help:

    
    function filter_function_name( $query_args, $sfid ) {    
        if($sfid==2978) {
    
         global $arr_product_ids;
    
          $query_args['tax_query'] = array(
            array(
              'key'     => 'post_product',
              'value'   => $arr_product_ids,
              'compare' => 'IN',
            ),
          );
    
        }    
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    
    #213626

    Anonymous
    Inactive

    Hi TJ,

    On your second example, did you try adding: global $arr_product_ids within the function too? Your trying to use $arr_product_ids variable.

    
    function filter_function_name( $query_args, $sfid ) {    
        if($sfid==2978) {
    
            global $arr_product_ids;
    
            $query_args['post_product'] = $arr_product_ids;
        }    
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    

    Anonymous
    Inactive

    Hi there,

    I have search and filter form where I need to set a custom meta query based on the values held within a dynamic array variable based on the user who is logged in (which controls what they see).

    So manually I tried the following:

    Post Meta > post_product = 1134

    Which is similar to what I want, and of course that works BUT I need the value of that query to be a dynamic array of product ID’s instead (held within $arr_product_ids in my example) depending on the user logged in, ie as follows:

    
       'meta_query' => array(
            'key'     => 'post_product',
            'value'   => $arr_product_ids,
            'compare' => 'IN',
        ),
    

    With that in mind, I have tried: https://searchandfilter.com/documentation/search-results/custom/ and added the following to my functions.php file but sadly this has not worked:

    
    
    global $arr_product_ids;
    
    $args = array(
        'post_type' => 'post',
        'posts_per_page' => 12,
        'category_name' => 'news',
        'meta_query'     => array(
            'relation' => 'AND',
            'post_product' => array(
                'key'     => 'post_product',
                'value'   => $arr_product_ids,
                'compare' => 'IN',
            ),
            'post_urgent' => array(
                'key'  => 'post_urgent',
                'compare' => 'EXISTS',
            ),
            'post_priority' => array(
                'key'  => 'post_priority',
                'compare' => 'EXISTS',
            ),
        ),
        'orderby'  => array( 'post_priority' => 'DESC', 'post_urgent' => 'DESC', 'date' => 'DESC' ),
    );
    $args['search_filter_id'] = 2978;
    $query = new WP_Query($args);
    
    

    I then looked at https://searchandfilter.com/documentation/action-filter-reference/ and tried adding the following to functions.php, but sadly again no luck:

    
    
    function filter_function_name( $query_args, $sfid ) {    
        if($sfid==2978) {
            $query_args['post_product'] = $arr_product_ids;
        }    
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    
    

    Please could you ket me know where I’m going wrong with this as I think I’m going around in circles sadly, whereas you will know the issue immediately I’m sure :).

    Many thanks,
    TJ

    #212527

    Anonymous
    Inactive

    To be honest I am not sure how to create that function – it’s a bit beyond my abilities.

    I tried this, but it made the search form stop working.
    function filter_function_name( $query_args, $sfid ) {

    //if search form ID = 225, the do something with this query
    if($sfid==26869)
    {
    //modify $query_args here before returning it

    $query_args[‘post_type’] = array( ‘practitioners’ );
    }

    return $query_args;
    }
    add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );

    Just to simply matters, I have removed all the functions.php code altogether for the time being. As you will see on the page, the pagination does not seem to work with the search form on the page. When I put in a manual pagination link of https://staging-universallifetools.kinsta.cloud/our-teachers/page/2 it works, but the actual pagination buttons do not seem to do anything, just refresh the page.


    Anonymous
    Inactive

    Thank you. So stick this in the theme functions, set to the correct form ID and add the same args per my wp_query. So I have ended up with:

    function filter_function_name( $query_args, $sfid ) {
        
        //if search form ID = 225, the do something with this query
        if($sfid == 4672)
        {
            //modify $query_args here before returning it
            $query_args['numberposts'] = -1;
            $query_args['posts_per_page'] = 25;
            $query_args['post_type'] = 'product';
            $query_args['post_status'] = 'publish';
            $query_args['meta_key'] = 'special_offer';
            $query_args['meta_value'] = true;
        }
        
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    

    I have left the rest of the settings as per my last message (including the wp_query on the special_offers template where I am displaying the products). When I view the page the filters are not populating as expected, I should be seeing options for colour and size but I just see one colour option, which when I apply renders no results.

    Am I doing something else wrong here?

    #207594

    In reply to: Including taxonomies


    Anonymous
    Inactive

    Thanks Trevor.

    I managed to get it working with this:

    function filter_aus_library ( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==14334)
    	{
    		//modify $query_args here before returning it
    		$query_args['tax_query'] = array(
      'relation' => 'OR', 
      array(
        'taxonomy' => 'library_country',
        'terms'    => '1497',
      ),
    	array(
        'taxonomy' => 'library_author',
        'terms'    => '2192',
      )
    );
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_aus_library', 20, 2 );
Viewing 10 results – 41 through 50 (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.