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
|
1 Answer
Reset to default 1Try this
if( has_term('pude', 'produkttype') || has_term('senge', 'produkttype')) {
get_template_part( 'partials/sections/section', 'trustpilot' );
}
get_the_terms()
function instead oftaxonomy_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