Support » Plugin: Menu Item Visibility Control » multiple conditions

  • i want to put two conditions on a menu item. each works separately, but i cant figure out how to combine them. i want a menu item to only appear on the archive page of a certain category and also on any post w/i that category. I’m using these:

    has_term( ‘sports’, ‘category’ ) || is_category( ‘Sports’ ),

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author shazdeh


    You have an extra , at the end. Try:

    has_category( 'sports' ) || is_category( 'sports' )

    Great that worked. Do you you know how to get it to work w/ a custom taxonomy? I’m using this has_term( ‘camden’, ‘town’ ) || is_town( ‘Camden’ ) and it works for the archive and a post that have that taxonomy. but then when i go to my site, the page is blank except for the lines of the menu.

    Plugin Author shazdeh


    I think you’re getting a fatal error as is_town is not a function. For that you have to use the is_tax function (info:

    has_term( 'camden', 'town' ) || is_tax( 'town', 'camden' )

    I’ve looked thru these forums, but couldnt find how to hide a menu for certain taxonomies. I found how to hide for pages, but that code doesnt to be working on my site. I am using this currently – ! has_term( ‘camden’, ‘town’ ) || ! is_tax( ‘town’, ‘camden’ ) to try to hide a menu item if the page or post has the town taxonomy of camden. It is not working.

    Plugin Author shazdeh


    Since you want the menu to show on neither of those conditions you have to use && operator, or use parentheses to clarify the !, like so:

    ! ( has_term( 'camden', 'town' ) || is_tax( 'town', 'camden' ) )

    Above snippet will hide the menu item if has_term or is_tax conditions are met.

    • This reply was modified 1 year, 6 months ago by shazdeh.

    I found this code in a different comment to show if a parent category, but its for product category. how do i translate it for my custom ‘town’ taxonomy’? I have several child taxonomies of a parent taxonomy and i want menus items to show / hide if posts are in any of the child taxonomies.

    has_term( get_terms( array( ‘child_of’ => 69, ‘taxonomy’ => ‘product_cat’, ‘fields’ => ‘names’ ) ), ‘product_cat’ )

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘multiple conditions’ is closed to new replies.