Search Results for 'sf_input_object_pre'

Forums › Forums › Search › Search Results for 'sf_input_object_pre'

Viewing 10 results – 101 through 110 (of 146 total)
  • Author
    Search Results
  • #161666

    Anonymous
    Inactive

    I solved the problem using the ‘sf_input_object_pre’ filter:

    add_filter('sf_input_object_pre', 'pas_filterlabels_aan', 10, 2);
    	function pas_filterlabels_aan($input_object, $sfid) {
    
    		if($input_object['name'] == '_sfm_vakdomein') {
    			foreach($input_object['options'] as $option) {
    				$term_id = $option->value;
    				if ($option->value) {
    					$term = get_term_by('id', $term_id, 'cursussoort');
    					$term_label = $term->name;
    					$option->label = $term_label.' ('.$option->count.')';
    				}
    
    			}
    			
    		}
    	
    	return $input_object;	
    	}

    Replace ‘_sfm_vakdomein’ by your input object name (is shown in the query string) and ‘cursussoort’ by your taxonomy slug.

    #160307

    Anonymous
    Inactive

    Thank you for your reply. Would my best bet be to insert custom classes using sf_input_object_pre then use jquery to insert html around them?

    #160225

    Anonymous
    Inactive

    Hi, I’m trying to wrap <li> items in the filter in a div so I can easily apply an accordion to them. I’ve been using sf_input_object_pre to modify the prefix and postfix but they don’t seem to insert anything into the HTML – can someone confirm what these attributes do? And if they don’t insert any prefix or postfix, is there a way I can add HTML to the filter list?
    Thanks.

    function filter_function_name($input_object, $sfid) {
    
    	if($input_object['type']!='checkbox') 	{
    		return $input_object;
    	}	
    	foreach($input_object['options'] as $key => $option) {
    		if ($option->attributes['class']="sf-level-0") {
    		      $input_object['options'][$key]->prefix = '<div>';
                          $input_object['options'][$key]->postfix= '</div>';
    		}
    	}
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
    #152293

    Anonymous
    Inactive

    OK Here it is. I needed to show the author name by last, first, and sometimes the username by last,first. So I have a hook (which yes, you put in functions.php) and I check the form id and the field we’re outputting, and process it based on what the values are.

    If we’re looking at the author field, i basically requery the entire author list, and regenerate the list completely. You can see I exclude some authors (like admin, and some other random people i didn’t want in the list)

    If it’s the user field, i do a loop and requery the user and then adjust the info.

    I think i wrote the two if statements at different times, because the second way could probably be applied to the first. Whatever, it works.

    function sf_edit_author_field_order($input_object, $sfid)
    {
    	if( in_array( $sfid, array( 3390, 3444, 3562 ) ) && $input_object['name'] == '_sf_author' ) {
            // requery the author list
            $author_args = array(
                'exclude_admin' => true,
                'hide_empty' => true,
                'meta_key' => 'last_name',
                'orderby' => 'meta_value',
                'order' => 'ASC',
                'exclude' => array( 429, 233, 558, 7 )
            );
            $user_query = new WP_User_Query( $author_args );
            $users = $user_query->get_results();
            $new_users = array();
            $new_users[] = (object) array(
                'label' => 'All Authors',
                'attributes' => array (
                    'class' => 'sf-level-0 sf-item-0'
                ),
                'value' => '',
                'count' => 0
            );
            // go through users and get their user_nicename and display_name
            foreach( $users as $user ) {
                $new_users[] = (object) array(
                    'attributes' => array(
                        'class' => 'sf-level-0'
                    ),
                    'value' => $user->user_nicename,
                    'label' => $user->last_name . ', ' . $user->first_name,
                    'count' => 1
                );
            }
            $input_object['options'] = $new_users;
    	} else if ( $sfid == 3444 && $input_object['name'] == '_sft_userlist' ) {
            // requery the tagged user list to get their names - last, first
            // go through the options part of the object and get the user id, and then the meta info for that
            foreach ($input_object['options'] as $option) {
                // get the user id from the term meta
                $temp_term = get_term_by( 'slug', $option->value, 'userlist');
                $temp_term->meta_user_id = get_term_meta( $temp_term->term_id, 'user_id', true );
                $last_name = get_user_meta( $temp_term->meta_user_id, 'last_name', true );
                $first_name = get_user_meta( $temp_term->meta_user_id, 'first_name', true );
                // overwrite the original label
                if ( $last_name && $first_name ) {
                    $option->label = $last_name . ', ' . $first_name;
                }
            }
        }
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'sf_edit_author_field_order', 10, 2);

    Anonymous
    Inactive

    Hi all

    I have a client that requires a specific url structure for their pages but would like to use one common filter on those pages, although having different fields selected by default depending on the page.

    I know it would makes sense to use archive pages, but it is very probable the client will want to add content to those pages so for now I am not considering them. But I could potentially use archive pages and add taxonomy images and the taxonomy description to the templates.

    I understand that the next major release of this plugin will have a pretty permalinks option but unfortunately I can’t wait.

    I have created “category” like pages and embedded the filter and shortcode to show results on each of those pages. I have also added a filter to sf_input_object_pre to set a default state to one of the fields, based upon the page id. The posts being filtered are a custom post type, trips, and I have used ACF fields instead of taxonomies in order to avoid a ridiculous amount of custom taxonomies.

    I could continue to write code for each page but it would be hard to maintain. Also it appears that although the default option shows as selected on the initial page view, the results don’t reflect this. But I suppose this could be overcome with just a bit of javascript used to click the submit button after the page is ready.

    The other option I see is to add an action to pre_get_posts to somehow limit what is shown. I quickly investigated this but it seemed a bit confusing. I limited the filter with this code:

    if($query->post_type == ‘search-filter-widget’)

    but haven’t really investigated further since it wasn’t obvious what needed to be changed.

    What path would you suggest I take? I have only added a couple ‘trips’ so I can easily change direction at this point.

    Support topiscs such as this one: https://support.searchandfilter.com/forums/topic/default-category-on-radio-selection/
    and this one:
    https://support.searchandfilter.com/forums/topic/rewrite-issue/

    were a great help but I get the idea there might be quicker solution. Any help you could give me would be greatly appreciated. I suppose the answer I am looking for is somewhere on these forums I just haven’t been able to find it !

    thanks
    Ken

    #141135

    Anonymous
    Inactive

    Do you mean to open the url

    https://support.searchandfilter.com/forums/search/sf_input_object_pre/
    instead of
    https://support.searchandfilter.com/forums/search/sf_input_object_pre+range/ ?

    I’m afraid i’ll need some more help Trevor, in any case I really appreciate your fast answers…

    #141127

    Trevor
    Participant

    Are these meta keys being searched with a Range field, because that would cause the problem. At this time you can sort of work around it (by using the Edit Query Argument filter to remove the unwanted range parameters). There will be snippets other users have posted on how they did this if you search for:

    sf_input_object_pre range

    #126699

    In reply to: Filter default values


    Anonymous
    Inactive

    Thanks for the link.

    I fixed it the following way:

    function filter_function_name($input_object, $sfid) {
      if($input_object['name']=='xxx') {
        $input_object['defaults'] = array("yyy");
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
    #114750

    Anonymous
    Inactive

    Hi,

    I need to apply a category filter onload rather than showing all categories. I’ve used the below code to set the default to ‘news’ and removed the all option. But it still loads all the posts rather than just the news post on load.

    add_filter(‘sf_input_object_pre’, function ($input_object, $sfid)
    {
    if(($input_object[‘name’]!=’_sft_category’))
    {
    return $input_object;
    }
    $input_object[‘defaults’] = array(“news”);
    array_shift($input_object[‘options’]);
    return $input_object;
    } , 10, 2);

    #105123

    Ross
    Keymaster

    Hi Javier

    You can do this with the current version..

    Take a look at the docs here:

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

    Nearly any value in any input object can be changed if you dig deep enough into the $input_object there are all kinds of things that can be changed.

    Tested locally, and updated to match your field name _sfm_precio, this should do the trick:

    function filter_range_dropdown($input_object, $sfid)
    {
    	
    	if($input_object['name']=='_sfm_precio')
    	{
    		//udpate this field before rendering
    		//if we want to filter the options generated, we need to make sure the options variable actually exists before proceeding (its only available to certain field types)
    		if(!isset($input_object['options']))
    		{
    			return $input_object;
    		}
    		
    		//now loop through the options in the field
    		foreach($input_object['options'] as $option)
    		{
    			//update every label, and prefix and suffix with $
    			$option->label = "$ ".$option->label." $";
    		}		
    	}
    
    	//always return the input object, even if we made no changes
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_range_dropdown', 10, 2);

    Hope that helps

Viewing 10 results – 101 through 110 (of 146 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.