Support

Account

Forum Replies Created

  • Hi John,

    Thanks for your response. And you definitly pointed me in the right direction. Using a filter that runs on all fields was the solution I was looking for. I now basically removed the whole filter that had the dynamic part and moved it all to the initialize method. I only had a nesting level issue so I switched to a the ‘afc/prepare_field’ filter instead.

    Just for your reference here’s my adjusted code (I only need to do a minor cleanup). And thanks again!

    
    add_filter('acf/prepare_field', function($field) {
    
        $fieldObject = get_field_object($field['key']);
    
        if(!str_starts_with($fieldObject['name'], 'select')){
            return $field;
        }
    
        $layouts = acf_get_fields('group_5f33b50973315')[0]['layouts'];
    
        $blocks = array_filter($layouts, function($layout){
            return in_array('source', array_column($layout['sub_fields'], 'name'));
        });
    
        foreach ($blocks as $block) {
            if($fieldObject['name'] !== 'select' . ucfirst($block['name'])){
                continue;
            }
    
            $field['choices'] = [];
    
            $groups = get_field($block['name'], 'options');
    
            foreach($groups as $group){
                $field['choices'][$group['groupID']] = $group['name'];
            }
        }
    
        return $field;
    });
    
  • Hi Nugerama,

    I’ve run into a similar situation myself a while back. The solution is more WordPress rather than ACF related. My suggestion would be to use the admin_head action hook to add custom CSS in WP-admin and simply hide the fields you don’t want to show. Most fields still need to be loaded in to be sure that the value isn’t lost. But those fields don’t need to be visible to the user for that.

    There are some fields though you can remove by simply removing them using the user_contactmethods filter. Like for example below:

    function update_contact_methods( $contactmethods ) {
    
        unset( $contactmethods['aim'] );
        unset( $contactmethods['jabber'] );
        unset( $contactmethods['yim'] );
    
        return $contactmethods;
    
    }
    add_filter( 'user_contactmethods', 'update_contact_methods' );

    Let me know if this worked for you or you need any further assistance or ideas.

  • If you need it in the same loop when you go through the repeater then you could try this:

    preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $texthtml, $image);
        echo $image['src'];

    Where of course the $texthtml is your WYSIWYG field.

  • If you need it in the same loop when you go through the repeater then you could try this:

    preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $texthtml, $image);
        echo $image['src'];

    Where of course the $texthtml is your WYSIWYG field.

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