Output content if either of two php variables are not empty. Works locally but not on live server?

StackOverflow https://stackoverflow.com/questions/23654509

Вопрос

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?

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top