Both WordPress and Statamic content management systems are built on PHP. Just like many other programming languages, PHP’s syntax for OR is two vertical lines, || ; PHP’s syntax for AND is two ampersands &&. Alternatively, the words “and” and “or” may be used, too.
IF OR in PHP
The following PHP code used in a WordPress template reads as: “If the phone field is empty OR the claims field is empty, then output the <p> tag reading “Contact us directly.”
<?php if( empty( $phone) || empty( $claims ) ) {
echo '<p>Contact us directly.</p>' ;} ?>
#alternative syntax for OR
<?php if( empty( $phone) or empty( $claims ) ) {
echo '<p>Contact us directly.</p>' ;} ?>
IF AND in PHP
The following PHP code used in a WordPress template reads as: “If the phone field AND claims field are empty then output the <p> tag ready “Contact us directly.”
<?php if( empty( $phone) && empty( $claims ) ) {
echo '<p>Contact us directly.</p>' ;} ?>
#alternative syntax for AND
<?php if( empty( $phone) and empty( $claims ) ) {
echo '<p>Contact us directly.</p>' ;} ?>
If this code snippet helped you, please let me know in the comments. You may also enjoy our other WordPress, PHP, coding logic, and Statamic articles.