Pergunta

I'm trying to check whether either of two variables are empty, and if either have content, then to output some html.

I'm using WordPress, and each variable is set to use a my_meta function which just gets the content of a meta box from the database. If both functions are empty, no code is output, but if either have content, then the code in the if statement is output.

<?php

$meta_1 = my_meta( 'metabox1' );
$meta_2 = my_meta( 'metabox2' );

if (!empty($meta_1 | $meta_2)) { ?>
    <div>
        <?php echo my_meta( 'metabox1' ); ?>
    </div>
    <div>
        <?php echo my_meta( 'metabox1' ); ?>
    </div>
<?php }

?>

Everything works fine on my local server using MAMP, but when I try the site on a live server, I get the following error.

Parse error: syntax error, unexpected '|', expecting ')'...

Is the code poorly written, or have I missed something?

Foi útil?

Solução

just change it to

if (!empty($meta_1) || !empty($meta_2)) {

it might be due to php versions or different return values form $meta_1 and $meta_2 between prod and localhost

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top