arie_cristianD

change category taxonomy for brand cpt

Jul 6th, 2026
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. add_filter(
  2.     'the_category',
  3.     function ( $thelist, $separator, $parents ) {
  4.         if ( 'brand' !== get_post_type() ) {
  5.             return $thelist;
  6.         }
  7.  
  8.         $brand_categories = get_the_term_list( get_the_ID(), 'brand-category', '', $separator );
  9.  
  10.         if ( empty( $brand_categories ) || is_wp_error( $brand_categories ) ) {
  11.             return $thelist;
  12.         }
  13.  
  14.         return $brand_categories;
  15.     },
  16.     10,
  17.     3
  18. );
  19.  
  20. add_filter(
  21.     'jnews_get_primary_category_filter',
  22.     function ( $category_id, $post_id ) {
  23.         if ( 'brand' !== get_post_type( $post_id ) ) {
  24.             return $category_id;
  25.         }
  26.  
  27.         $brand_categories = wp_get_post_terms(
  28.             $post_id,
  29.             'brand-category',
  30.             array(
  31.                 'fields' => 'ids',
  32.             )
  33.         );
  34.  
  35.         if ( is_wp_error( $brand_categories ) || empty( $brand_categories ) ) {
  36.             return $category_id;
  37.         }
  38.  
  39.         return (int) $brand_categories[0];
  40.     },
  41.     20,
  42.     2
  43. );
Advertisement
Add Comment
Please, Sign In to add comment