Support

Account

Home Forums Backend Issues (wp-admin) Custom Location Rules for Media types

Unread

Custom Location Rules for Media types

  • Hi ACF Forum

    Can anyone help me with this please.

    I’ve tried to set up a filter where I can display a field set only when editing an audio file in the Media Library (as opposed to pdfs, images, docs etc)

    I looked at the documentation in the ACF website and found the page “Custom location rules” – managed to sort the “Add Custom Field Types” by adding the following code to the site’s functions file.

    
    add_filter('acf/location/rule_types', 'acf_location_rules_types');
    function acf_location_rules_types( $choices )
    {
        $choices['Other']['media'] = 'media';
    
    	return $choices;
    }
    

    aHowever when trying to edit the example of the “Add Custom Values” I changed the ACF example (which use users) to the following:

    
    add_filter('acf/location/rule_values/media', 'acf_location_rules_values_media');
    function acf_location_rules_values_media( $choices )
    {
        $media = get_media();
     
        if( $media )
        {
            foreach( $media as $media )
            {
                $choices[ $media->data->ID ] = $media->data->display_name;
            }
        }
     
        return $choices;
    }
    

    I had to guess a lot of it and it came back saying “Parse error: syntax error, unexpected T_VARIABLE in /data04/records/public_html/wp-content/themes/Futureproof/functions.php on line 37″

    Could anyone tell me what this piece of code should be. As I said at the beginning of this post I’m looking to display a field set only when editing an audio file in the Media Library and not display the field set when looking at pdfs, images and other media types.

    Many thanks

    Phil

Viewing 1 post (of 1 total)

The topic ‘Custom Location Rules for Media types’ is closed to new replies.