• Hi,

    I am using this code without a problem to printf the key1 value of a post:
    <?php $meta = get_post_meta( $post_id, $KEY1, $single ); ?>
    <?php printf( $meta ); ?>

    Now I have a KEY2 as well for the same $meta. Can you help what is the code to printf key1 when key2 is empty and viceversa?

    Thanks for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You’d probably want to do something along the lines of

    <?php
    if( !empty( $KEY1) ) {
        $meta = get_post_meta( $post_id, $KEY1, $single );
    }
    
    if( !empty( $KEY2) ) {
        $meta = get_post_meta( $post_id, $KEY2, $single );
    }
    
    printf( $meta );
    ?>

    Alternatively, you could just have two meta variables that you check for each key.

    Thread Starter maximmmus

    (@maximmmus)

    Hey!
    Thank you

    Alternatively, you could just have two meta variables that you check for each key.

    How would this code look like?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘get post meta for 2 keys’ is closed to new replies.