Ich möchte die Produkt-Tags der WooCommerce Produkte in einer Reihe bekommen, denn mit ihm if/else-Logik zu tun (in_array), aber mein Code funktioniert nicht:WooCommerce Erhalten Sie Produkt-Tags in Array
<?php
$aromacheck = array() ;
$aromacheck = get_terms('product_tag') ;
// echo $aromacheck
?>
Beim Echo von $ aromatecheck bekomme ich nur ein leeres Array, obwohl die Produkt-Tags existieren - sichtbar in der Post-Klasse.
Wie bekomme ich die Produkt-Tags in einem Array richtig?
Solution (dank Noman und Nevius):
/* Get the product tag */
$terms = get_the_terms($post->ID, 'product_tag');
$aromacheck = array();
if (! empty($terms) && ! is_wp_error($terms)){
foreach ($terms as $term) {
$aromacheck[] = $term->slug;
}
}
/* Check if it is existing in the array to output some value */
if (in_array ("value", $aromacheck)) {
echo "I have the value";
}
Es * gibt * ein Array von Objekten zurück. Sie können ein Array von Objekten nicht "echo" ... – rnevius
Das war wirklich nützlich –