add_shortcode( 'filter_product', 'filter_product_shortcode' ); function filter_product_shortcode( $atts ) { $atts = shortcode_atts( array( 'taxid' => '34' ), $atts, 'show_post' ); ob_start(); $args = array( 'hierarchical' => 1, 'show_option_none' => '', 'hide_empty' => 1, 'parent' => $atts['taxid'], 'taxonomy' => 'product_cat' ); $subcats = get_categories($args); echo '<ul class="wooc_filter_main"><li data-filter="*" class="filter-active">All</li>'; foreach ($subcats as $sc) { $link = get_term_link( $sc->slug, $sc->taxonomy ); $filter = strtolower($sc->name); $filter = str_replace(" ", "-", $filter); $filter = str_replace(array("'", "\"", """), "", $filter); echo '<li data-filter="'.$filter.'">'.$sc->name.'</li>'; } echo '</ul>'; $myvariable = ob_get_clean(); return $myvariable; }
Jagdish Sarma Asked question November 25, 2021