Wordpress - display categories with subcategories of specific parent category - wordpress

I want to display categories with nested subcategories of specific parent that I know the id of. I want to use wp_list_categories function. Here is my code:
$args = array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'show_count' => 0,
'hierarchical' => 1,
'title_li' => '',
'hide_empty' => 0,
'parent' => 20
);
wp_list_categories($args);
Categories of parent with the id of 20 are displaying correctly, but their children(subcategories) are not showing. What can be the solution here?

change: 'parent' => 20 to 'child_of' => 20

Related

Woocommerce > wp_list_categories 'hide_empty' ignored

I have a problem with wp_list_categories code that I can't figure out.
I've tried everything to exclude the empty categories, but it doesn't work.
If I use the woocommerce widget, the categories get hidden, but with my code they don't :( I need to make it custom and not use the widget because I have custom configurations.
This is my code:
`$sidebar = array(
'taxonomy' => 'product_cat',
'orderby' => 'meta_value',
'meta_key' => 'categories_order_agr',
'order' => 'ASC',
'show_count' => 0,
'hierarchical' => 1,
'hide_empty' => true,
'exclude' => $specialiID,
'child_of' => $get_product_cat_ID,
);
wp_list_categories($sidebar);`
Can anyone help me?

Get Wordpress Tags With 0 Posts Count

I'm trying to get some tags from wordpress database, tags that aren't assigned to any posts, so their post count is 0.
The code i use selects only the tags with 1 or more posts assigned...
<?php
$args = array(
'smallest' => 12,
'largest' => 24,
'unit' => 'px',
'format' => 'flat',
'orderby' => 'name',
'order' => 'DESC',
'exclude' => null,
'include' => null,
'topic_count_text_callback' => 'default_topic_count_text',
'link' => 'view',
'taxonomy' => 'post_tag',
'echo' => true,
'child_of' => null,
'show_count' =>1
);
?>
How can i get the tags with 0 posts assigned to show?
Set hide_empty to false in the arguments of the get_tags function.
get_tags(array('hide_empty' => false));
If you're using custom taxonomy, use get_terms function.
get_terms('custom_tags', array('hide_empty' => false));

Issue with Woocommerce and wp_list_categories displaying empty categories

I have this code pulling together a category:
$args = array(
'taxonomy' => 'product_cat',
'title_li' => '<h2 class="cat-title">Categories</h2>',
'exclude' => '588',
'hide_empty' => '1',
'show_count' => '1'
);
wp_list_categories( $args );
Which gives me a list of categories to a depth of 2 or 3. Unfortunately for some reason the empty sub categories are still being displayed and I cannot see why.

custom post type wp_dropdown_categories

How can i customize wp_dropdown_catagories to show custom posts. Let say posts created by woocommerce. Here is my code which shows blog posts. But I want custom posts in dropdown. How can I achieve that?
<?php $args = array(
'show_option_all' => 'All Catagories',
'show_option_none' => '',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 1,
'hide_empty' => 0,
'child_of' => 0,
'exclude' => '1,5',
'echo' => 1,
'selected' => 0,
'hierarchical' => 0,
'name' => 'cat',
'id' => '',
'class' => 'postform',
'depth' => 1,
'tab_index' => 0,
'taxonomy' => 'category',
'hide_if_empty' => false,
); ?>
<?php wp_dropdown_categories( $args ); ?>
Resolved this. Added taxonomy of woocommerce in above code. Just replace value for taxonomy in product_cat.
'taxonomy' => 'product_cat',

How do you embed the Wordpress Categories widget in a page/post outside the sidebar?

Rather than use another widget I want to code the method to include the WP "Categories" widget directly within the content of a page or post.
Any ideas?
You can also use a plugin called Widgets on Pages and then just drag Categories into the newly created "sidebar" - then you just put the shortcode [widgets_on_pages] anywhere you want to use it.
To add wordpress post categories into the template file you need to use
<?php wp_list_categories($args); ?>
Default arguments are :
<?php $args = array(
'show_option_all' => ,
'orderby' => 'name',
'order' => 'ASC',
'show_last_update' => 0,
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => ,
'feed_type' => ,
'feed_image' => ,
'exclude' => ,
'exclude_tree' => ,
'include' => ,
'hierarchical' => true,
'title_li' => __( 'Categories' ),
'show_option_none' => __('No categories'),
'number' => NULL,
'echo' => 1,
'depth' => 0,
'current_category' => 0,
'pad_counts' => 0,
'taxonomy' => 'category',
'walker' => 'Walker_Category' );
?>
or you can simply use it without parameters, in that case defaults will work.
<?php wp_list_categories(); ?>
you can read more about this function here
I think, you search for this.
https://wordpress.stackexchange.com/questions/36511/are-widgets-meant-to-be-used-outside-of-sidebars

Resources