Woocommerce > wp_list_categories 'hide_empty' ignored - wordpress

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?

Related

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));

How to make WP get_terms orderby array

How can I sort terms using two values?
I'm using this:
$papers = get_terms(
array(
'taxonomy' => 'paper',
'hide_empty' => false,
'orderby' => array(
'year' => 'DESC',
'number' => 'DESC'
),
'order' => 'DESC'
));
But I know get_terms doesn't accept array for orderby.
I've searched a lot but there are not valid solutions or maybe I didn't find the right one.
What can I try?
Use get_terms_orderby filter from wordpress
check these references.
https://developer.wordpress.org/reference/hooks/get_terms_orderby/
http://hookr.io/filters/get_terms_orderby/
https://wp-kama.com/hook/get_terms_orderby

Wordpress - display categories with subcategories of specific parent category

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

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

Wordpress - Filter by Taxonomy

Something weird happening in my query and can't see what's wrong
I am passing the variable THEME from a select list.
THe theme is pulled from the taxonomy THEME
so my code looks like
$thetheme = $_GET['theme'];`
$thetheme is correctly passed from URL
then
$args2 = array(
'tax_query' => array(
array(
'taxonomy' => 'theme',
'field' => 'slug',
'terms' => $thetheme
)
),
'post_type' => array( 'post', 'dvd' ),
'cat' => '31',
'paged' => $paged,
'posts_per_page' => $listitems,
'order' => 'DESC',
'orderby' => 'date',
'query' => $wp_query
);`
The query is working only on some Post, not all of them, and cant understand why.
If I select a post with the Theme "Adventure" for example, it will pull the correct amount of post.
But an other post, in the same category with a different theme, will not be displayed.
This is puzzling me....
HElP!
thx
Don't think you need here to run complete taxonomy query... try this =)
$args2 = array(
'theme' => $thetheme,
'post_type' => array( 'post', 'dvd' ),
'cat' => '31',
'paged' => $paged,
'posts_per_page' => $listitems,
'order' => 'DESC',
'orderby' => 'date',
'query' => $wp_query
);

Resources