Hi, I have tis code <'.if (get_post_meta($post->ID,"_as_roomtype",true) == 'DE').'> <a href="'.get_permalink().'" class="readnow" >"---NAME---"</a> Code (markup): I have values on "meta_value" like "DE", "UK", "SP" I need to make something like that. if the value on ""meta_value" = "DE" show Germany on "---NAME---" if the value on ""meta_value" = "UK" show United Kingdom on "---NAME---" if the value on ""meta_value" = "SP" show Spain on "---NAME---" How can I make this? Thank you for your help
If you only have a few of these, and feel okay doing this manually, you can just assign the values to an array, something like this: $countries = array(0 => array(1 => 'DE', 2=> 'Germany'), 1 => array(1 => 'UK', 2 => 'United Kingdom'), 2 => array(1 => 'SP', 2 => 'Spain')); PHP: and then do something like this: for ($i = 0; $i < count($countries); $i++) { echo '<'.if (get_post meta($post->ID,"_as_roomtype",true) == $countries[$i][1]).'> <a href="'.get_pemalink().'" class="readnow">'.$countries[$i][2].'</a>'; } PHP: I think that should work, haven't tested it though
Try something like this: <?php $meta_values = array('DE' => 'Germany', 'UK' => 'United Kingdom', 'SP' => 'Spain'); if ($meta_key = get_post_meta($post->ID,"_as_roomtype",true)): ?> <a href="<?php echo get_permalink() ?>" class="readnow" ><?php echo $meta_values[$meta_key]; ?></a> Code (markup):
First of, where the hell is $meta_key assigned? And second, the $meta_key is not compared, it's assigned, and will always return whatever the get_post_meta is returning....
Hi, Thank you very much for your help. Already try many combinations. Last combination is $meta_values = array('DE' => 'Germany', 'UK' => 'United Kingdom', 'SP' => 'Spain'); if ($meta_key = get_post_meta($post->ID,"_as_roomtype",true)); Code (markup): I have to put ; instead of : on ..._as_roomtype",true)); if I put : gives me a error. I try to insert the code like this <a href="' . get_permalink() . '"><a href="' . get_permalink() . '" class="readnow" ><?php echo $meta_values[$meta_key]; ?></a> Code (markup): gives me empty spaces. I try to make like this only to test <a href="' . get_permalink() . '"><a href="' . get_permalink() . '" class="readnow" >'.$meta_values.'</a> Code (markup): and gives me array
A better test would be: <a href="' . get_permalink() . '"><a href="' . get_permalink() . '" class="readnow" >'.$meta_key.'</a> PHP: What do you get for that? I have a feeling its a case sensitive issue, in which case can be solved by: <a href="' . get_permalink() . '"><a href="' . get_permalink() . '" class="readnow" ><?php echo $meta_values[strtoupper($meta_key)]; ?></a> PHP: