Forums Forums Search & Filter Pro Change Post Type labels

Tagged: ,

Viewing 4 posts - 1 through 4 (of 4 total)
  • Anonymous
    #39990

    Hello there,

    I would like to be able to modify the label of some post types… for example I don’t like the post type Media to be called Media and would like it to be called Photo on the Search input filter.

    Could you be so kind to address me on how to change the labels?

    Thank you!

    Ross Moderator
    #39999

    Hi Daniel

    In general I think the ideal scenario is to change the label of the post type itself – if that is not possible (in the case of Media), S&F has a filter which allows you to filter the options of any input object:

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

    Be sure to check the github example too for how to change the label of an option.

    Thanks

    Anonymous
    #40004

    Perfect,

    I’ve done it… it works great. Thank you!

    For someone curious about how to implement this, on your plugin php add the following function:

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

    Hope it helps.

    Ross Moderator
    #40124

    Thanks for the update Daniel 🙂

Viewing 4 posts - 1 through 4 (of 4 total)