WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get two post meta keys and values print array (3 posts)

  1. Pete
    Member
    Posted 1 year ago #

    I'm using this code <?php $meta = get_post_meta( get_the_ID() ); print_r ($meta);?> which prints an array of all the meta keys for a post. I need to modify the function to only display the meta key custom1, and custom2. So that the output when printed shows the value/keyws of custom1 and custom2

  2. Frumph
    Member
    Posted 1 year ago #

    For meta keys that only have one entry per key

    $meta_keys = array('custom1', 'custom2');
    foreach ($meta_keys as $key) {
            $key_value = get_post_meta($post->ID, $key, true);
            if (!empty($key_value)) echo 'Key: '.$key.' Value: '.$key_value;
    }

    The question is, do you you have more then one value and multiple keys of the same name?

  3. Pete
    Member
    Posted 1 year ago #

    Excellent thank you

Topic Closed

This topic has been closed to new replies.

About this Topic