wordpress - When I add custom post type permalink rewrite, my regular post permalinks stop working. Can't get both to work at the same time -
really struggling one, appreciated. site has both regular post posts, , custom post type called "articles."
i'm trying work regular posts use /%category%/postname%/ permalink structure, (which have set in settings). working fine, until add custom rewrite article post type. i'd articles follow /%issue%/%postname%/ structure. can working great following:
add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 ); function wpa_show_permalinks( $post_link, $id = 0 ){ $post = get_post($id); if ( is_object( $post ) && $post->post_type == 'article' ){ $terms = wp_get_object_terms( $post->id, 'issue_tax' ); if( $terms ){ return str_replace( '%issue%' , $terms[0]->slug , $post_link ); } } return $post_link; } where post type registered this:
function article_post_type() { $labels = array( 'name' => _x( 'magazine articles', 'post type general name', 'text_domain' ), 'singular_name' => _x( 'magazine article', 'post type singular name', 'text_domain' ), 'menu_name' => __( 'magazine articles', 'text_domain' ), 'name_admin_bar' => __( 'magazine articles', 'text_domain' ), 'parent_item_colon' => __( 'parent article:', 'text_domain' ), 'all_items' => __( 'all articles', 'text_domain' ), 'add_new_item' => __( 'add new article', 'text_domain' ), 'add_new' => __( 'add new', 'text_domain' ), 'new_item' => __( 'new article', 'text_domain' ), 'edit_item' => __( 'edit article', 'text_domain' ), 'update_item' => __( 'update article', 'text_domain' ), 'view_item' => __( 'view article', 'text_domain' ), 'search_items' => __( 'search article', 'text_domain' ), 'not_found' => __( 'not found', 'text_domain' ), 'not_found_in_trash' => __( 'not found in trash', 'text_domain' ), ); $rewrite = array( 'slug' => '%issue%', 'with_front' => false, 'pages' => true, 'feeds' => true, ); $args = array( 'label' => __( 'article', 'text_domain' ), 'description' => __( 'magazine articles , features', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', ), 'taxonomies' => array( 'issue_tax', 'category', 'featured_media', 'tag' ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-welcome-write-blog', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'rewrite' => $rewrite, 'capability_type' => 'page', ); register_post_type( 'article', $args ); } add_action( 'init', 'article_post_type', 0 ); i add that, reset permalink settings, , article permalinks start working indended - - working, regular posts start displaying 404.
why unable both work @ same time? missing piece somewhere?
thanks advice!
-erin
just follow question - perhaps thing i'm struggling why post_type_filter function affecting more article post type have specified?
thanks, erin
ok, 1 more super strange thing. works if pass query parameter @ end of custom post links, works: http://www.mysitename.com/spring-2015/test-article-here/?post_type=article gives me 404 http://www.mysitename.com/spring-2015/test-article-here/
why be? i'm sorry many questions, trying bottom of this..!
thanks again, erin
Comments
Post a Comment