0

I have a serious problem :)

I have this code:

<?php global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'provinciadestacada', true); ?>

And i want include here:

<?php if ( in_category( '951' )) { echo 'Online'; }
else
?>

After else i want get post_meta "provinciadestacada"

Maybe something like this?

<?php if ( in_category( '951' )) {
echo 'Online. Todas las provincias'; }
else echo "global $wp_query;
$postid = $wp_query->post->ID;
$meta = get_post_meta($postid, 'provinciadestacada', true);"
?>

closed as off-topic by s_ha_dum, tfrommen, gmazzap, fuxia Dec 31 '13 at 0:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?" – s_ha_dum, tfrommen, gmazzap, fuxia
If this question can be reworded to fit the rules in the help center, please edit the question.

  • What you are doing is just very, very bad PHP. You need to construct a string and echo that, not try to echo the actual PHP like that. – s_ha_dum Dec 30 '13 at 20:58
  • @s_ha_dum Can you help me with code example please? I'm new in programmation and i must learn a lot. The first code works fine, but i don't know how implement that – Vektor Unbreakable Dec 30 '13 at 21:04
1

Use it like this

<?php if ( in_category( '951' )) {
echo 'Online. Todas las provincias'; }
else { 
      global $wp_query;
      $postid = $wp_query->post->ID;
      $meta = get_post_meta($postid, 'provinciadestacada', true);
     echo $meta;
 }

?>

To do it in reverse as you want:

  global $wp_query;
  $postid = $wp_query->post->ID;
  $meta = get_post_meta($postid, 'provinciadestacada', true);

   if(!empty($meta)) {
        echo $meta;
   }

    elseif(in_category( '951' )) {
        echo 'Todas las provincias';
     }

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