Actually I have custom attributes in product for after this create searches for these attributes , the case it´s I try show all attributes and values but no get finally
For example actually I have the attribute called colors, in this attribute I have different values, red, green yellow, blue
For show the attributes and his values i use this code :
<?php global $product; $terms=get_terms('pa_colors'); print "<select>"; foreach ($terms as $each_term) { echo '<option>'.$each_term->name.'</option>'; } print "</select>"; ?>
The case it´s this function only show me 2 colors and no the rest of colors, I see in the woocommerce backend I have only 2 products and have these colors that show with this function , but no the other colors, the case it´s in the backend of woocommerce for attributes I can see all attributes and colors and I want show the same as backend but in front, but this function no let me show all values for this attribute called colors.
How do I use only 2 color from attribute called colors only show me these 2 colors but no the others.
My question is, how can I show all colors or all values from one attribute in the front?
The result must be this :
<select>
<option>Red</option>
<option>Green</option>
<option>Yellow</option>
<option>Blue</option>
</select>
Thanks for the help. Regards
When using
get_terms()
, WordPress filters out terms that aren’t attached to published posts (and WooCommerce stores your products as posts). Luckily, WordPress will allow you to prevent this from happening. Try the following:Many other options are explained in the codex: https://codex.wordpress.org/Function_Reference/get_terms
Use this SQL Query to get all attributes with details
try:
Example:
Return: