So I’ve got some repetitive code below that, when an admin adds a new product category, I have to go in make and make sure I add yet another block of code with the newly added category.
if(is_product_category( 'animal' )) {
$args = array(
'post_type' => 'product',
'product_cat' => 'animal',
'posts_per_page' => 999,
'orderby' => 'name',
'order' => 'ASC',);
} elseif(is_product_category( 'character' )) {
$args = array(
'post_type' => 'product',
'product_cat' => 'character',
'posts_per_page' => 999,
'orderby' => 'name',
'order' => 'ASC',);
} elseif(is_product_category( 'kids' )) {
$args = array(
'post_type' => 'product',
'product_cat' => 'kids',
'posts_per_page' => 999,
'orderby' => 'name',
'order' => 'ASC',);
}
...
Since the only thing changing is the conditional statement and the product category array, I’m thinking there’s a way to write one block of code that’ll just take each newly created category and auto do it so I don’t have to go back in.