Advertisement
arie_cristianD

show category label on custom post type

Dec 15th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.40 KB | None | 0 0
  1. add_filter( 'jnews_primary_category', 'get_cat_custom_post_type', 99, 2 );
  2.  
  3.  
  4. function get_cat_custom_post_type( $category_id, $post_id ) {
  5.     if ( null === $category_id ) {
  6.         $categories = array_slice( get_the_category( $post_id ), 0, 1 );
  7.         if ( empty( $categories ) ) {
  8.             return null;
  9.         }
  10.         $category    = array_shift( $categories );
  11.         $category_id = $category->term_id;
  12.     }
  13.  
  14.     return $category_id;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement