I'm fairly new to PHP so sorry if its something elementary.
I'm trying to modify my shop template, so that I can list certain icons for each tag. I installed ACF pro and created a custom_image for product_tag
it is called: tag_taxonomy_image
I managed to create a loop which checks for a certain tag (right now it's 1EUR) and echos if it is found.
I'm trying to output the image associated with this product_tag, but I can't. I'm trying to follow this document: /
I'm modifying the content-product-php, and here's my code currently:
<?php
/* Get the product tag */
$terms = get_the_terms( $post->ID, 'product_tag' );
$product_tag_check = array();
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
$product_tag_check[] = $term->name;
}
}
/* Check if it is existing in the array to output some value */
if(in_array('1EUR',$product_tag_check)) {
$term = get_term_by( 'id', $child, $taxonomy_name );
$image = get_field('tag_taxonomy_image', $term); //'tag_taxonomy_image' is our field name
$size = 'thumbnail'; // (thumbnail, medium, large, full or custom size)
echo '1EUR tag exists';
echo $image['url'];
echo wp_get_attachment_image( $image, $size );
?>
<?php } else {
echo '1EUR tag does not exist';
}
?>
Any recommendations on what I'm missing?
I'm fairly new to PHP so sorry if its something elementary.
I'm trying to modify my shop template, so that I can list certain icons for each tag. I installed ACF pro and created a custom_image for product_tag
it is called: tag_taxonomy_image
I managed to create a loop which checks for a certain tag (right now it's 1EUR) and echos if it is found.
I'm trying to output the image associated with this product_tag, but I can't. I'm trying to follow this document: https://www.advancedcustomfields/resources/image/
I'm modifying the content-product-php, and here's my code currently:
<?php
/* Get the product tag */
$terms = get_the_terms( $post->ID, 'product_tag' );
$product_tag_check = array();
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
$product_tag_check[] = $term->name;
}
}
/* Check if it is existing in the array to output some value */
if(in_array('1EUR',$product_tag_check)) {
$term = get_term_by( 'id', $child, $taxonomy_name );
$image = get_field('tag_taxonomy_image', $term); //'tag_taxonomy_image' is our field name
$size = 'thumbnail'; // (thumbnail, medium, large, full or custom size)
echo '1EUR tag exists';
echo $image['url'];
echo wp_get_attachment_image( $image, $size );
?>
<?php } else {
echo '1EUR tag does not exist';
}
?>
Any recommendations on what I'm missing?
Share Improve this question asked Jan 22, 2020 at 13:02 Pbalazs89Pbalazs89 1151 silver badge12 bronze badges 3 |1 Answer
Reset to default 0to grab the ACF data you will need to use $tag_tax_image = get_field('tag_taxonomy_image', $post->ID);
From there I recommend doing a var_dump($tag_tax_image);
to figure out how to access the data you need.
echo $image['url'];
orecho wp_get_attachment_image( $image, $size );
. I'd start by dumping $image and $term, e.g.print_r( $term );
to check they look correct. But I haven't used ACF for a while - it might be best asking them for help if you get stuck. – Rup Commented Jan 22, 2020 at 13:15