Title: PHP Logic
Last modified: August 21, 2016

---

# PHP Logic

 *  [Palemo](https://wordpress.org/support/users/palemo/)
 * (@palemo)
 * [12 years ago](https://wordpress.org/support/topic/php-logic/)
 * Hi, I have a fairly straight forward piece of PHP code:
 *     ```
       <?php
   
       $menu_to_count =  wp_nav_menu( array(
         'theme_location' => 'primary',
         'sub_menu' => true,
         'echo' => false
       ) );
   
       $menu_items = substr_count( $menu_to_count, 'class="menu-item ' ); 
   
       if ( $menu_items != 0 ) { wp_nav_menu( array('theme_location' => 'primary','sub_menu' => true,'direct_parent' => true) );
       									} else {
       										echo "none"; } ?>
       ```
   
 * The problem is the line wp_nav_menu( array(‘theme_location’ => ‘primary’,’sub_menu’
   => true,’direct_parent’ => true) ) for when it evaluates to true. If I change
   that to a simple echo (“yes”) then it is fine – which means I must be missing
   some logic. Any thoughts?

The topic ‘PHP Logic’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Palemo](https://wordpress.org/support/users/palemo/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/php-logic/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
