WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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;
share|improve this answer
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
thanks for the answer – Fnarp Jun 4 '11 at 11:21

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;
share|improve this answer
thanks for the answer – Fnarp Jun 4 '11 at 11:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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