最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom taxonomy - Show template part if part of term

programmeradmin3浏览0评论

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' );
    }

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' );
    }
Share Improve this question edited Dec 17, 2019 at 10:03 gmatta 4323 silver badges8 bronze badges asked Dec 17, 2019 at 9:27 webmaster touchewebmaster touche 32 bronze badges 2
  • 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 Commented Dec 17, 2019 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 Commented Dec 17, 2019 at 11:02
Add a comment  | 

1 Answer 1

Reset to default 1

Try this

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

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

}
发布评论

评论列表(0)

  1. 暂无评论