Get main term from a sub term in Woocommerce

code function wc_origin_trail_ancestor( $link = false, $trail = false ) { if (is_product_category()) { global $wp_query; $q_obj = $wp_query->get_queried_object(); $cat_id = $q_obj->term_id; $descendant = get_term_by(“id”, $cat_id, “product_cat”); $descendant_id = $descendant->term_id; $ancestors = get_ancestors($cat_id, ‘product_cat’); $ancestors = array_reverse($ancestors); $origin_ancestor = get_term_by(“id”, $ancestors[0], “product_cat”); $origin_ancestor_id = $origin_ancestor->term_id; $ac = count($ancestors); } else if ( is_product() ) { … Read more

Is there An Input Checkbox Option That Works like `wp_dropdown_categories()` To Use In A WP Search Form?

Yes, there is a built-in WordPress function you can use to render a list of checkboxes (or simply, checklist) which then allows the user to select multiple terms, and the function is wp_terms_checklist(). However, the function only works for users who have the capability/permission to assign terms to a post, so you’d need to create … Read more

Randomly placed sticky custom posts complemented by blog posts

This did it: $products = get_posts(array(‘post_type’ => ‘products’)); $numbers = range(0, 8); shuffle($numbers); $x = 0; foreach($products as $post) : setup_postdata($post); $product = new WP_Query(array(‘p’=>$post->ID,’post_type’=>’products’)); if (!empty($product->posts)) array_splice($posts,$numbers[$x],0,$product->posts); $x++; endforeach; foreach($posts as $post) : setup_postdata($post); …

Custom Taxonomy terms with latest post ordered by date pagination issue

to change the number of posts per page you can do it in the wp dashboard like in this picture This function on functions.php works for me function tcPostsPerPage( $query ) { if (is_home()){$query->set(‘posts_per_page’, 6);} if (is_archive()){$query->set(‘posts_per_page’, 6);} } add_action( ‘pre_get_posts’, ‘tcPostsPerPage’ ); the two 6 is limiting to 6 per page, if this doest … Read more

List taxonomy terms plus their latest post ordered by post date

Right now you are performing the query by term, and displaying results instantly. What you need is to gather the results of each query, sort them and then display separately. Make sure to read code comments. /* $custom_terms = get_terms(‘columna’); – this approach is depreciated */ $custom_terms = get_terms( array( ‘taxonomy’ => ‘columna’ ) ); … Read more