I have a post meta field registrazione_singolaonothat has 2 value:


If one of these value is selected (in every post the first or the latter must be used) i want to show another custom meta field.

For example: if the value of the custom meta field is


It should display:

<?php  if((get_post_meta( $post->ID, 'registrazione_multipla', true))) { ?>
<?php echo get_post_meta( $post->ID, 'registrazione_multipla', true ); ?>
<?php } ?>

If it is:


it should display another big piece of php functions. I searched both on the codex, on this site and on google without getting any understandable help. Thanks. Any help is appreciated

1 Answer 1


I would store the meta value in a variable, and use an if/elseif statement to determine what should be displayed, like so:

$registrazione_singolaono = get_post_meta( $post->ID, 'registrazione_singolaono', true );
$registrazione_multipla = get_post_meta( $post->ID, 'registrazione_multipla', true );

if ( 'singolo_file' == $registrazione_singolaono && ! empty( $registrazione_multipla ) ) {
    echo $registrazione_multipla;
} elseif ( 'piu_file' == $registrazione_multipla ) {
    // something else
  • Please add an explanation to your code Sep 30, 2015 at 11:45
  • @PieterGoosen Done
    – Nate Allen
    Sep 30, 2015 at 12:20
  • @NateAllen your code is not working, but i am trying to adapt it. Firstly i think that the first line should be $registrazione_singolaonothat and not $registrazione multipla, that is another field that will be visualized only if the value of registrazione_singolaonothat is singolo_file
    – Benjamin
    Oct 1, 2015 at 15:43
  • @Benjamin Ok, I updated the code. I also added a check to make sure the $registrazione_multipla wasn't empty before echoing it.
    – Nate Allen
    Oct 1, 2015 at 16:21
  • I put the code between <?php and ?> and it doesn't work. I am i doing something wrong? It doesn't display anything @NateAllen
    – Benjamin
    Oct 1, 2015 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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