Forums Forums Search Search Results for 'sf_input_object_pre function'

Viewing 10 results - 61 through 70 (of 106 total)
  • Author
    Search Results
  • #214935

    Trevor
    Participant

    Spotted another errod, sorry.

    function add_miles_to_filter_labels($input_object, 2116) {
      if($input_object['name']!='_sfm_distance[]') {
        return $input_object;
      }
      foreach($input_object['options'] as $option) {
        $option->label .= " miles";
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);
    #214927

    Trevor
    Participant

    It shouldn’t have the dollar symbol, no.

    I can see an error also, so try this:

    function add_miles_to_filter_labels($input_object, 2116) {
      if(($input_object['name']!='_sfm_distance[]') {
        return $input_object;
      }
      foreach($input_object['options'] as $option) {
        $option->label .= " miles";
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);
    #214925

    Anonymous
    Inactive

    ok this is what I have so far:

    function add_miles_to_filter_labels($input_object, $2116) {
      if(($input_object['name']!='_sfm_distance[]') {
        return $input_object;
      }
      foreach($input_object['options'] as $option) }
        $option->label .= " miles";
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);

    I’ve tried with and without the $ sign in front of the id, but I still get a parse error on the site.

    #214907

    Trevor
    Participant

    I would imagine the PHP would be something like:

    function add_miles_to_filter_labels($input_object, $sfid) {
      if(($input_object['name']!='_sfm_colours') {
        return $input_object;
      }
      foreach($input_object['options'] as $option) }
        $option->label .= " miles";
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);

    where you change $sfid to the actual ID of the form AND
    where you change the string/name _sfm_colours to whatever the data_sf_field_name actually is, for example, see here:

    https://www.screencast.com/t/wlh2lKrVDj4

    #214759

    Anonymous
    Inactive

    Hello to update this I have now got the the code working correctly. Here shows 2 text replacement one after the other.

    function my_plugin_search_filter_change_label($input_object, $sfid) {
     if ($sfid == 845 && $input_object['name'] == '_sft_category') {
          
      foreach ($input_object['options'] as $key => $option) {
          if ($option->label == 'All Categories') {
    
            $input_object['options'][$key]->label = 'Toutes Catégories';
          }
        }
      foreach ($input_object['options'] as $key => $option) {
          if ($option->label == 'Accessories and Cables') {
    
            $input_object['options'][$key]->label = 'Accessoires et Câbles';
          }
        }
      }
     return $input_object;
    }
    
    add_filter('sf_input_object_pre', 'my_plugin_search_filter_change_label', 10, 2);
    #214482

    Anonymous
    Inactive

    I have tried it in the functions.php but I cant seem to get it to change word ‘Brochures’ to ‘Test’

    This is the code I have used am I missing something?

    <?php
    function my_plugin_search_filter_change_label($input_object, $sfid) {
      if ($sfid == 845 && $input_object['name'] == '_sft_file_type[]') {
        foreach ($input_object['options'] as $key => $option) {
          if ($option->label == 'Brochures') {
            $input_object['options'][$key]->label = 'Test';
          }
        }
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'my_plugin_search_filter_change_label', 10, 2);
    ?>
    #214457

    Anonymous
    Inactive

    I have found this however it as sfid ==12345 what do you use to replace 12345? Would this be a more correct snippet.

    function my_plugin_search_filter_change_label($input_object, $sfid) {
      if ($sfid == 12345 && $input_object['name'] == '_sf_post_type') {
        foreach ($input_object['options'] as $key => $option) {
          if ($option->label == 'Media') {
            $input_object['options'][$key]->label = 'Photos';
          }
        }
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'my_plugin_search_filter_change_label', 10, 2);
    #214427

    Anonymous
    Inactive

    I am trying this code from the documentation you supplied. However it just removes all the options.
    How can I use this correctly?

    <?php
    function filter_input_object($input_object, $sfid)
    {
    foreach($input_object['options'] as $option)
    	{
    		if($option->value=="brochures")
    		{//the option with no value is always the "all items" or unselected state
    			$option->label = "Brochures";
    		}
    		else if($option->value=="brochures")
    		{//we want to change the label for the option "black" - we can feed back in the count number to the label for this field type
    			$option->label = "test (".$option->count.")";
    	}
    	}
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
    ?>
    #206792

    Anonymous
    Inactive

    Trevor, you are awesome! Thanks for troubleshooting again. Would not have arrived at this on my own.

    FINAL code:

    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 = "Search by Author";
          } else {
            $user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option->value );
    	if ($user->display_name=='') {
    	  unset($input_object['options'][$key]);
    	} else {
    	  $input_object['options'][$key]->label = $user->display_name . ' (' . $option->count . ')';  
    	}
          }
        }
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);

    Anonymous
    Inactive

    FINAL code:

    Okay, so the code required included that original bit. Here is the final code in the inc/template-tags.php file:

    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( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
                'meta-prep meta-prep-author',
                sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
                    get_permalink(),
                    esc_attr( get_the_time() ),
                    get_the_date()
                ),
                coauthors_posts_links( null, null, null, null, false )
            );
        else:
            printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
                'meta-prep meta-prep-author',
                sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
                    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', 'twentyten' ), get_the_author() ) ),
                    get_the_author()
                )
            );
        endif;
    }
    endif;
    
    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 = "Search by Author";
          } 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);

    Also, added Relevanssi plugin per your guidance and enabled it within SF Pro search form > Advanced settings.

    Really appreciate your continued support on this issue! Glad to have it resolved now.

Viewing 10 results - 61 through 70 (of 106 total)