MetaBox equivalent to `the_content` filter

Support General MetaBox equivalent to `the_content` filterResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #40418
    brandonjpbrandonjp
    Participant

    I'm currently using code like this:
    \add_filter( 'the_content', 'filter_keywords' );
    And it works with my filter_keywords function to change the output of default Post or Page content.

    But I would also like to filter text stored and displayed from post meta custom fields. For example, I have a custom field called extra_info that I would like to run through my filter_keywords filter.

    What would be the MetaBox.io way to do this? I've tried doing something similar to add_filter( 'rwmb_meta',... at the bottom of this page: https://docs.metabox.io/filters/rwmb-the-value/ - but not having any luck.

    Thank you.

    #40420
    brandonjpbrandonjp
    Participant

    I think I was having an issue with priority and shortcodes. This seems to be working now, but if there is a better or more preferred way, I'm interested to know. Thank you!

    add_filter( 'rwmb_meta', function( $value, $field_id, $args, $object_id ) {
        // look for my custom fields
        $filterThese = array('extra_info','user_notes','manager_notes');
        if ( in_array($field_id, $filterThese, true) ) {
            // run my custom field values through the filter
            return filter_keywords($value);
        }
        return $value;
    }, 99, 4 );
    
    #40423
    brandonjpbrandonjp
    Participant

    Sorry, I hit the back button and I thought I was editing my post. 🤦‍♀️ 🙂

    #40440
    PeterPeter
    Moderator

    Hello Brandon,

    Thanks for sharing the solution.

    I see it is the correct way to filter the field value when outputting with the helper function rwmb_meta(). Refer to the documentation https://docs.metabox.io/filters/rwmb-meta/

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.