I want to know if there is a way that 2 different custom fields that have basicly the same value function to be combined.

1) meta_name: my_link and meta_value: a link 2) meta_name: other_link and meta_value: other link

It should work like this: The general call in my template is

<?php if ( get_post_meta($post->ID, 'my_link', true) ) : ?>

<?php echo $my_link; ?>

<?php endif; ?>

So if in the post is present meta_name: other_link and not my_link and in the template is queried my_link, I want the other_link meta_name to be recognized as meta_name: my_link.

I searched all over. Thanks in advance.


you can use the same meta_key for multiple values, for example:

meta_key - 'links' meta_value - 'link1'

meta_key - 'links' meta_value - 'link2'

then you can get the meta as an array of links:

$links = get_post_meta($post->ID, 'links');
if ($links){
    foreach ($links as $link){
        echo $link;
  • First, thanks for the answer, I know that but the I can not control the custom fields, I only control the query from the theme for the custom field (I know I can make all the same meta_key from database, but as I said I can do that because I control only the theme) the custom fields are are created by two plugins and I want the theme to be compatible with both meta_keys. – Fnarp Jun 3 '11 at 17:20
  • I see what you mean, then i guess you can always add an elseif before your end if, let me know if thats ok – Bainternet Jun 3 '11 at 18:29

Why don't you retrieve both values and then decide which to use? As (messy) one liner it can be expressed like this:

    ( $my_link = get_post_meta($post->ID, 'my_link', true) )
    ( $my_link = get_post_meta($post->ID, 'other_link', true) )
    echo $my_link;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.