Home > Back-end >  Wordpress PHP Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b
Wordpress PHP Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b

Time:06-30

I have a WordPress sidebar on my site that works fine on an old version of PHP, but now on production, the page will not load. This is caused by incorrect formatting of the line below, which is flagging an error due to Unparenthesized a ? b : c ? d : e not being supported.

This is the line:

$taxonomy = get_the_terms($post->ID, is_singular('post') ? 'category' : is_singular('blog') ? 'category' : is_singular('event') ? 'category' : 'vacancy_category');

I have tried multiple formats of the parenthesis to no avail. Any advice would be greatly received.

CodePudding user response:

You can try:

$taxonomy = get_the_terms($post->ID, (is_singular('post') ? 'category' : (is_singular('blog') ? 'category' : (is_singular('event') ? 'category' : 'vacancy_category'))))

However even though this doesn't ocupy too much space, I feel like it's hard to read. You could use an if else instead to make it more readable.

  • Related