Search Results for 'sf_input_object_pre function label'

Forums › Forums › Search › Search Results for 'sf_input_object_pre function label'

Viewing 10 results – 51 through 60 (of 68 total)
  • Author
    Search Results

  • Trevor
    Participant

    Ok, so it must go in the file you suggested.

    The only bock of code you would have need to add was this, I think:

    function filter_function_name($input_object, $sfid) {
      if ($input_object['name'] == '_sft_author') {
        global $coauthors_plus;
        foreach($input_object['options'] as $key => $option) {
          if($option->value=="") {
            $option->label = "All Authors";
          } else {
            $user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option->value );
    	$input_object['options'][$key]->label = $user->display_name . ' (' . $option->count . ')';
          }
        }
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);

    The question is, is that code working? Does the field show ‘All Authors’ in the choice box?

    If so, if you edit just that one line to change that label, does it then change in the front end?


    Anonymous
    Inactive

    Thanks for your quick response, Trevor. However, I had tried that solution before posting here and it did not work for me. I’m using a child of the Visual Theme. When adding the CoAuthors plugin to the site, this was the code I added into my template-tags.php file in my child theme:

    if ( ! function_exists( 'visual_posted_on' ) ) :
    /**
     * Integrate Co-Authors Plus with TwentyTen by replacing twentyten_posted_on() with this function
     */
    function visual_posted_on() {
        if ( function_exists( 'coauthors_posts_links' ) ) :
            printf( __( '%2$s &nbsp;<span style="color:#999;">/</span>&nbsp; %3$s', 'visual' ),
                'meta-prep meta-prep-author',
                sprintf( '<span class="entry-date">%3$s</span>',
                    get_permalink(),
                    esc_attr( get_the_time() ),
                    get_the_date()
                ),
                coauthors_posts_links( null, null, null, null, false )
            );
        else:
            printf( __( '%2$s &nbsp;<span style="color:#999;">/</span>&nbsp; %3$s', 'visual' ),
                'meta-prep meta-prep-author',
                sprintf( '<span class="entry-date">%3$s</span>',
                    get_permalink(),
                    esc_attr( get_the_time() ),
                    get_the_date()
                ),
                sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
                    get_author_posts_url( get_the_author_meta( 'ID' ) ),
                    esc_attr( sprintf( __( 'View all posts by %s', 'visual' ), get_the_author() ) ),
                    get_the_author()
                )
            );
        endif;
    }
    endif;

    Then, I added the Trial by Fire code after:

    // Trial by fire
    
    function filter_function_name($input_object, $sfid) {
    
    	if ($input_object['name'] == '_sft_author') {
    
    		global $coauthors_plus;
    		
    		//udpate this field before rendering
    
    			foreach($input_object['options'] as $key => $option) {
    
    				if($option->value=="")
    					{//the option with no value is always the "all items" or unselected state
    						$option->label = "All Authors";
    					}
    
    				else {
    
    				$user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option->value );
    
        			$input_object['options'][$key]->label = $user->display_name . ' (' . $option->count . ')';
    
        			}
    
            	}
    
    	}
    	
    	return $input_object;
    
    }
    
    add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);

    But still no dice. I’m not sure what I’m missing here, but what should be happening is that when I search for Wael in the search box or even in the dropdown Authors box he should be appearing. But he is not. I would appreciate any further help you can provide. I am stumped.

    #196334

    Anonymous
    Inactive

    Hello Team,

    No matter where I search, I can’t find a way to make the plugin run on page load.

    Once I start clicking around, the ajax filtering works fine, but I need it to work on the first page load too.

    We are using the code below to remove one of the options and to set the default active item. This all works fine.

    // Remove “All Courses” option and set main to default on Our Menu.
    add_filter( ‘sf_input_object_pre’, function ( $input_object, $sfid ) {
    if ( $sfid == 120 ) {
    // var_dump($input_object);
    if ( ( $input_object[‘name’] = ‘_sft_course’ ) ) {
    if ( empty( $input_object[‘defaults’][0] ) ) {
    $input_object[‘defaults’] = [ ‘main’ ];
    }
    $key = array_search( ‘All Courses’, array_column( $input_object[‘options’], ‘label’ ) );
    if ( $key !== false ) {
    unset( $input_object[‘options’][ $key ] );
    $input_object[‘options’] = array_values( $input_object[‘options’] );
    }
    }
    }

    return $input_object;
    }, 10, 2 );

    Can you please tell me how to instruct the plugin to run in the fresh page load?
    I can’t find the answer anywhere in the docs or internet.

    Thank you very much,
    Kota

    #193165

    Anonymous
    Inactive

    Hi Trevor,

    This is the code we’ve used btw. Maybe it’s useful 🙂

    function filter_function_name($input_object, $sfid)
        {
            if($input_object['name']=='_sfm_kalender_datum')
            {
                foreach($input_object['options'] as $option) {
                    if($option->value != "") {
                        $date = strtotime( $option->label );
                        $option->label = date('d m Y', $date);
                    }
                }
            }
            
            return $input_object;
        }
        add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
    #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.

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

    #82378

    Anonymous
    Inactive

    All of a sudden the search forms have stopped sorting. The page is here: https://intrepidexposures.com/photo-tours/

    Tweaks to code as per previous threads here:

    // Search Filter
    function filter_input_object($input_object, $sfid) {
    	
    if(($input_object['name'] == '_sfm_workshop_location') || ($input_object['name'] == '_sfm_tour_style') || ($input_object['name'] == '_sfm_tour_leader')) {
    
    		
    		$new_options = array(); //the options added to this will replace all existing optoins in the field
    		
    		foreach($input_object['options'] as $option) {
    			
    			if ($option->value !== "")
    			{
    				//check to see if the option has a parent
    				$parent_id = wp_get_post_parent_id($option->value);
    				if(!$parent_id)
    				{
    					//then this option does not have a parent, so it must be a parent itself, add it to the new array
    					$option->label = get_the_title($option->value);
    					array_push($new_options, $option);
    				}
    			}
    		}
    		
    		//now we have an array with only parent options in, so simply replace the one in the input object
    		$input_object['options'] = $new_options;
    		
    	}
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);

    Any ideas?

    #71326

    Anonymous
    Inactive

    I’m trying to set dropdown options programmatically.
    But all of options on dropdown come out with “selected” attribute.
    How do I set selected attribute properly to single option currently selected?

    function sf_input_object_pre_mod($input_object,$sfid){
      if($sfid==123){ 
        if($input_object['name']=='_sfm_event_month'){
          $mons[] =  date('Y-m', strtotime(date('Y-m-01')));
          for($i=1;$i<=11;$i++){ $mons[] =  date('Y-m', strtotime(date('Y-m-01').' +'.$i.' month')); }
          foreach($mons as $k=>$m){ $opt = new StdClass();
             $opt->label = $m; $opt->attributes = array('class'=>'sf-level-0'); $opt->values = $m; $opt->count = 0;
             $input_object['options'][] = $opt; }
        }
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre','sf_input_object_pre_mod',10,2);
    #61395

    Anonymous
    Inactive

    I recently upgraded to the latest version and now it is calling an error. Any ideas?

    function filter_input_object($input_object, $sfid) {
    	if(($input_object['name'] == ('_sfm_workshop_location' || '_sfm_tour_style' || '_sfm_tour_leader'))) {
    		foreach($input_object['options'] as $option) {
    			if ($option->value !== "") {
      					$option->label = get_the_title($option->value);
    				}
    			}
    		return $input_object;
    	} else {
    	return $input_object;
    	}
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
Viewing 10 results – 51 through 60 (of 68 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.