wp_list_categories depth and number

You should add ‘child_of’ => 0, That way you will display only Main categories aka children of 0. $custom_args = array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘child_of’ => 0, ‘depth’ => 1, ‘number’ => 4, ); wp_list_categories($custom_args); If you want to get WooCommerce categories try this: function getCustomProductCats () { $orderby = ‘name’; $order=”asc”; … Read more

shop page with all categories with paginate

i think it is petty straightforward solution first get your all categories list by help of get_categories() function and loop though and find the post relative with that. <?php $categories = get_categories(); return all categories foreach( $categories as $cat ){ $query = new WP_query([‘cat’=>$cat->term_id, ‘postes_per_page’=> 10]); if( $query->have_postes() ){ echo $cate-name; // this this category … Read more

Inserting Category programmatically

Keep track of the return value of wp_insert_term and use it to build your structure. A successful return value will be an array with a term_id key that you can pass into wp_insert_term‘s $args array as parent. $parent = wp_insert_term(‘Science’, ‘category’); // I’ll leave out `$args` here if (is_wp_error($parent)) { // insert didn’t work! return … Read more

Show archives by year from just one category

If I understand you question clearly that we just need to get post in that submenus from only cat id = 4 , this will make your archive.php to work only for cat id = 4 Please add below code to functions.php: function wpse75668_filter_pre_get_posts( $query ) { if ( $query->is_main_query() && ! is_admin() ) { … Read more

using checked function to verify value against an array

OK Try the below $current = get_user_meta($user_id, ‘continent’, $true); $categories = get_categories( $args ); foreach ( $categories as $category ){ ?> <label><input type=”checkbox” id=”type-<?php echo $category->name; ?>” value=”<?php echo $category->name; ?>” class=”shopping” name=”top_level[]” <?php checked($category->name, $current); ?>><?php echo $category->name; ?> </label> <?php } If $current = get_user_meta($user_id, ‘continent’, $true); value is an array then try … Read more