Get category id of next / prev post inside the_post_navigation

Here was my final solution: $next_post = get_next_post(); if (!empty( $next_post )){ $next_categories = get_the_terms($next_post->ID,’category’); $next_cat_data = get_option(‘category_’.$next_categories[1]->term_id); if (isset($next_cat_data[‘hex’])){ echo “<style>div.nav-next:hover{background-color:”.$next_cat_data[‘hex’].”;} div.nav-next:hover span.post-title, div.nav-next:hover span.meta-nav {color:#f8f7f4;}</style>”; } } $previous_post = get_previous_post(); if (!empty( $previous_post )){ $prev_categories = get_the_terms($previous_post->ID,’category’); $prev_cat_data = get_option(‘category_’.$prev_categories[1]->term_id); if (isset($prev_cat_data[‘hex’])){ echo “<style>div.nav-previous:hover{background-color:”.$prev_cat_data[‘hex’].”;} div.nav-previous:hover span.post-title, div.nav-previous:hover span.meta-nav {color:#f8f7f4;}</style>”; } }

Show Subcategory Name Instead of Parent Category

$terms = get_terms( [‘taxonomy’ => ‘some-taxonomy’, ‘parent’ => 123 ] ); // or $categories = get_categories( [ ‘parent’ => 123 ] ); Where the parent id is the one you want to get the subcategory from. This gives you all subcategories/-terms in an array. You can access data like name or term_id. For getting the … Read more

Assign post category to a page by selecting category from page dashboard

add this code into functions.php and a taxonomy box will be created for page from where user can make categories for page. <?php add_action( ‘init’, ‘create_book_tax’ ); function create_book_tax() { register_taxonomy( ‘genre’, ‘page’, array( ‘label’ => __( ‘Genre’ ), ‘rewrite’ => array( ‘slug’ => ‘genre’ ), ‘hierarchical’ => true, ) ); } ?>

Getting child category id (help with improving my code)

Starting from your parent category slug you can use the following code to get the child categories: $parent = get_category_by_slug(‘winners-2018’); $catz = get_categories( array( ‘parent’ => $parent->cat_ID ) ); foreach ($catz as $cat_archive) { // No need for get_category(); because get_categories() already returns category objects … }