I'm not an educated programmer, but usually i can put existing code together so it works the way i want it to. But this time i'm lost, i feel like i've tried everything.

I'm trying to only show a template part if the product is part of a specific term. This is one of the numerous code snippets i've tried.

I hope it makes sense to what i'm trying if not i'll answer any questions :)

 $taxonomy = taxonomy_exists( 'produkttype' );
 if ( $term = 'pude' && $term = 'senge' ) {
      echo get_template_part( 'partials/sections/section', 'trustpilot' );
  • Use the get_the_terms() function instead of taxonomy_exists(). In your code you only check if the term has been defined, not if it is assigned/associated to the post. Look at accepted answer in this question. – nmr Dec 17 '19 at 10:18
  • Thank you for your answer. I had tried the get_the_terms, just not in the correct way. I now know what the taxonomy_exists () does, thank you :) – webmaster touche Dec 17 '19 at 11:02

Try this

if( has_term('pude', 'produkttype') || has_term('senge', 'produkttype')) {

   get_template_part( 'partials/sections/section', 'trustpilot' );

  • This seems to work, thank you very much for your fast reply! – webmaster touche Dec 17 '19 at 11:00
  • @webmastertouche great, consider marking it as right answer. – Gangesh Dec 17 '19 at 11:01
  • Yes of course, it's done :) – webmaster touche Dec 17 '19 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.