Filter Dropdown options

Forums › Forums › Search & Filter Pro › Filter Dropdown options

Viewing 7 posts – 1 through 7 (of 7 total)
  • Anonymous
    #34104

    Hi,

    I was wondering if it is possible to filter the values of a dropdown to change them from post ID to post title?

    I’ve seen this https://gist.github.com/rmorse/7b59b45a14b1ca179868 but php is not my strong point and so I’ve hit a brick wall.

    Currently my dropdown is populated with a custom meta field and is displaying the associated post ID’s. I’d like to change those ID’s using get_the_title(); to instead show the post title.

    Please can you offer any advice on how to do this?

    Thanks

    Anonymous
    #34363

    Any updates on this please???

    Anonymous
    #34365
    This reply has been marked as private.
    Ross Moderator
    #34366

    Hi Jacob sorry for the delay.

    You’re almost there.

    First, you have only 1 = in the first if statement.

    So it does the code for every single field – this needs to be changed to a double ==

    Second, I think likely you got the fieldname wrong – see here on how to get the correct fieldname:

    http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/#How_to_get_the_field_name

    Here is your code updated (and I’m guessing the field name is from meta data, otherwise you need to find the name as link just above:

    <?php
    function filter_input_object($input_object, $sfid) {
    	
    	if(($input_object['name'] == '_sfm_workshop_location')) {
    		
    		foreach($input_object['options'] as $option) {
    			$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);
    
    ?>

    Thanks

    Anonymous
    #34372
    This reply has been marked as private.
    Anonymous
    #34373

    Perfect, ACF relationship fields are working perfectly now 🙂

    Ross Moderator
    #34382

    🙂

Viewing 7 posts – 1 through 7 (of 7 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.