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);"
?>
2
  • 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
    Commented Dec 30, 2013 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 Commented Dec 30, 2013 at 21:04

1 Answer 1

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';
     }
0

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