I have an attribute:
- Name(label): Box Size
- Slag: box-size
I tried this code:
$attribute_slug = 'pa_box-size';
// Get the term object based on the attribute slug
$term = get_term_by('slug', $attribute_slug, 'pa');
if ($term) {
$attribute_label = $term->name; // Attribute label
$attribute_id = $term->term_id; // Attribute ID
// Output the attribute label and ID
echo 'Attribute Slug: ' . $attribute_slug . '<br>';
echo 'Attribute Label: ' . $attribute_label . '<br>';
echo 'Attribute ID: ' . $attribute_id;
} else {
echo 'Attribute not found: ' . $attribute_slug;
}
But got always "Attribute not found: pa_box-size".
2
Answers
I solved my problem with this:
Source: wordpress.stackexchange.com
So I will just need an IF statement to check a specific attribute.