我注册了一个自定义帖子类型:“jobs”
// set up labels
$labels = array(
\'name\' => \'Jobs\',
\'singular_name\' => \'Job\',
\'add_new\' => \'Add New Job\',
\'add_new_item\' => \'Add New Job\',
\'edit_item\' => \'Edit Job\',
\'new_item\' => \'New Job\',
\'all_items\' => \'All Jobs\',
\'view_item\' => \'View Job\',
\'search_items\' => \'Search Jobs\',
\'not_found\' => \'No Jobs Found\',
\'not_found_in_trash\' => \'No Jobs found in Trash\',
\'menu_name\' => \'Jobs\',
);
//register post type
register_post_type( \'jobs\', array(
\'labels\' => $labels,
\'has_archive\' => \'jobs\',
\'public\' => true,
\'supports\' => array(
\'title\',
\'editor\',
\'excerpt\',
\'thumbnail\',
\'page-attributes\'
),
\'exclude_from_search\' => false,
\'capability_type\' => \'post\',
\'query_var\' => true,
\'menu_icon\' => \'dashicons-book-alt\',
\'rewrite\' => array(
\'slug\' => \'jobs/%job_status%\',
\'with_front\' => false
),
)
);
和自定义分类:“状态”
$labels = array(
\'name\' => _x( \'Status\', \'taxonomy general name\', \'trademanager\' ),
\'singular_name\' => _x( \'Status\', \'taxonomy singular name\', \'trademanager\' ),
\'search_items\' => __( \'Search Statuses\', \'trademanager\' ),
\'all_items\' => __( \'All Statuses\', \'trademanager\' ),
\'parent_item\' => __( \'Parent Status\', \'trademanager\' ),
\'parent_item_colon\' => __( \'Parent Status:\', \'trademanager\' ),
\'edit_item\' => __( \'Edit Status\', \'trademanager\' ),
\'update_item\' => __( \'Update Status\', \'trademanager\' ),
\'add_new_item\' => __( \'Add New Status\', \'trademanager\' ),
\'new_item_name\' => __( \'New Status Name\', \'trademanager\' ),
\'menu_name\' => __( \'Status\', \'trademanager\' ),
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'jobs/%job_status%\', \'with_front\' => false ),
);
我希望URL是:jobs/**特定状态(如类别)**/post
我找到了这个函数:
function tm_jobs_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == \'jobs\' ){
$terms = wp_get_object_terms( $post->ID, \'status\' );
if( $terms ){
return str_replace( \'%job_status%\' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( \'post_type_link\', \'tm_jobs_permalinks\', 1, 2 );
这很好地创建了url,但它只返回404错误。我做错了什么?