Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

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

if(
    ( $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
add comment

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
add comment

Your Answer

 
discard

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.