Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://ja.wordpress.org/support/topic/複数カテゴリーの場合、パーマリンクになるカテ/ */
- function change_post_link_category( $cat, $cats, $post ) {
- $cats_id = array_map( function ( $cat ) {
- return $cat->term_id;
- }, $cats );
- $category = false;
- $post_meta = get_post_meta( $post->ID, 'permalink_cat', true );
- if ( is_numeric( $post_meta ) )
- $category = get_term( absint( $post_meta ), 'category' );
- if ( ! $category )
- $category = get_term_by( 'slug', $post_meta, 'category' );
- if ( $category && in_array( $category->term_id, $cats_id ) )
- return $category;
- return $cat;
- }
- add_filter( 'post_link_category', 'change_post_link_category', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment