Eliminating the appearance of a specific custom field in a post

I would like to suppress the output of one of my custom fields. Is there a way to do this using the <?php the_meta(); ?>command?

Related posts

Leave a Reply

2 comments

  1. The function, the_meta() allows you to hook to the the_meta_key filter (which currently is not documented in the Codex); this is where it fires off:

    // wp-includes/post-templates.php @line 744
    echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>n", $key, $value);
    

    http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/post-template.php#L735

    This filter is applied to each and every meta pair, which means that you can add a filter to suppress based on a specific key, value or key/value pair like so:

    function wpse31274_exclude_my_meta( $html, $meta_key, $meta_value ) {
        if( 'remove_this_key' != $meta_key )
            return $html;
        return '';
    }
    add_filter( 'the_meta_key', 'wpse31274_exclude_my_meta', NULL, 3 );
    

    Tried and tested, seems to work, so I hope it helps.

  2. Have you tried with delete_post_meta($post_id, $key, $value);?

    Since the_meta has not any parameter maybe delete_post_meta is your best option, however I’m totally guessing, I would need to know the context of your project in order to give you a better answer :)!