There is a lovely function get_term_link()
, which you can use to get the any WP_Term
object archive page URL.
Just add this inside your foreach
loop:
$url = get_term_link( $attribute );
Edit
Since you need to retrieve a certain meta value for each attribute, try fetching them all and var_dumping them, to see what is it exactly that you need.
For example:
/** @var \WP_Term[] $attributes */
$attributes = get_terms( 'pa_couleurs' );
foreach ( $attributes as $attribute ) {
echo $attribute->name;
// Get all attribute meta data
$meta = get_term_meta( $attribute->term_id );
// Dump it out on the page. Remove after you find the key(s) you need
echo '<pre>';
print_r( $meta );
echo '</pre>';
// After finding the exact meta key that holds the info you need, edit this
$images = (array) get_term_meta( $attribute->term_id, 'change_this', true );
// This will probably hold the array of attachment IDs, so you'll need to get the URL's from that
foreach ( $images as $image_id ) {
// Get image src from ID
$src = wp_get_attachment_image_url( $image_id, 'thumbnail' );
// If src is found
if ( $src ) {
echo '<img src="' . $src . '" alt="Attribute Image">';
} // If not
else {
echo 'No image src for the image ID ' . $image_id . '<br>';
}
}
}