Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function jnews_get_primary_category( $post_id ) {
- $category_id = null;
- if ( get_post_type( $post_id ) === 'post' ) {
- $category = vp_metabox( 'jnews_primary_category.id', null, $post_id );
- $cat = get_term( $category );
- if ( ! empty( $category ) && isset( $cat ) ) {
- $category_id = $category;
- } else {
- $categories = array_slice( get_the_category( $post_id ), 0, 1 );
- if ( empty( $categories ) ) {
- return null;
- }
- $category = array_shift( $categories );
- $category_id = $category->term_id;
- }
- }
- return apply_filters( 'jnews_primary_category', $category_id, $post_id );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement