previous/next_post_link in the same sub-category?

If you’ll take a look at next_post_link Codex page, you’ll see it’s usage: <?php next_post_link( $format, $link, $in_same_term = false, $excluded_terms=””, $taxonomy = ‘category’ ); As you can see, third param is in_same_term and it’s default value is false. If you set it to true, then the function will return next post from same category. … Read more

Assign category from custom field on post creation and update

After getting year, you may check if category exists using category_exists($cat_name); if not found then create category using wp_create_category( $cat_name, $parent ); after that you may create post using $my_post = array( ‘post_title’ => wp_strip_all_tags( $_POST[‘post_title’] ), ‘post_content’ => $_POST[‘post_content’], ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_category’ => array( 8,39 ) ); // Insert the … Read more

How to exclude children categories of parent category

$categories = get_categories( array( ‘exclude_tree’ => array(40) )); In both get_categories() and wp_list_categories() you can use the exclude_tree parameter instead of exclude. exclude_tree (array|string) Array or comma/space-separated string of term ids to exclude along with all of their descendant terms. If $include is non-empty, $exclude_tree is ignored. Default empty array.