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