The task is as follows. We have a product card template in Elementor, we have products with tags. The task is to use the Portfolio tool to display images of products that belong to the same label as the product that we visited.
I understand this can be done by creating a certain filter and adding it to the query id. I tried adding this code via snippet in Query ID in the Query field in the Portfolio block , but it doesn't work
$output = array();
// get an array of the WP_Term objects for a defined product ID
$terms = wp_get_post_terms( get_the_id(), 'product_tag' );
// Loop through each product tag for the current product
if( count($terms) > 0 ){
foreach($terms as $term){
$term_id = $term->term_id; // Product tag Id
$term_name = $term->name; // Product tag Name
$term_slug = $term->slug; // Product tag slug
$term_link = get_term_link( $term, 'product_tag' ); // Product tag link
// Set the product tag names in an array
$output[] = '<a href="'.$term_link.'">'.$term_name.'</a>';
}
// Set the array in a coma separated string of product tags for example
$output = implode( ', ', $output );
// Display the coma separated string of the product tags
echo $output;
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744647842a4585721.html
评论列表(0条)