I have been researching all over the net and forums regarding my question but I can't seem to produce the correct results. Basically I'm trying to display the terms or product attributes for only a specific product category.
Here is the code I have been working on.
<fieldset class="liquor-types-control filter-controls" >
<?php
$terms = get_terms( 'wine', /*<--Product Category */ 'pa_liquor-types' /* <--Product Attribute */);
foreach ( $terms as $term ) :
?>
<label>
<input type="checkbox" value="<?php echo "." . $term->slug ?>" />
<?php echo $term->name ?>
</label>
<?php endforeach; ?>
</fieldset>
(
[errors] => Array
(
[invalid_taxonomy] => Array
(
[0] => Invalid taxonomy.
)
)
[error_data] => Array
(
)
)
Go to WooCommerce → Settings, select the Products tab, and then choose the Display option. For each of the Shop Page Display and Default Category Display options, select Show products. Save your changes.
These two shortcodes will display your product categories on any page. [product_category] – Will display products in a specified product category. [product_categories] – Will display all your product categories.
The var_dump
is showing that you are using taxonomies on WordPress. While I don't have experience directly with Wordpress, the Wordpress site docs say:
Prior to 4.5.0, the first parameter of get_terms() was a taxonomy or list of taxonomies:
Since 4.5.0, taxonomies should be passed via the ‘taxonomy’ argument in the $args array:
From the function reference:
$term = get_term( $term_id, $taxonomy );
Gives you term slug: e.g.: term-slug-example
$slug = $term->slug;
Gives you term name: e.g. Term Name Example
$name = $term->name;
First, make sure you are using the correct version - you are using the syntax from prior 4.5.0
Second, the error is saying that the taxonomy pa_liquor-types
is invalid. You need to check where this is being defined.
Check your create_initial_taxonomies()
function syntax and post it if necessary.
try something like this:
<?php
$terms = get_terms( 'wine', 'pa_liquor-types');
foreach($terms as $term) { ?>
<input type="checkbox" value="<?php echo "." . $term['slug'];?>"/>
<?php echo $term['name'];?>
<?php } ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With