我正在构建一个使用WP Job Manager的网站。我对设置它很感兴趣,以便URL显示为:
/category/region/name/
我发现
this link that explains how to do just that 并添加了以下代码:
function job_listing_post_type_link( $permalink, $post ) {
// Abort if post is not a job
if ( $post->post_type !== \'job_listing\' ) {
return $permalink;
}
// Abort early if the placeholder rewrite tag isn\'t in the generated URL
if ( false === strpos( $permalink, \'%\' ) ) {
return $permalink;
}
// Get the custom taxonomy terms in use by this post
$categories = wp_get_post_terms( $post->ID, \'job_listing_category\', array( \'orderby\' => \'parent\', \'order\' => \'ASC\' ) );
$regions = wp_get_post_terms( $post->ID, \'job_listing_region\', array( \'orderby\' => \'parent\', \'order\' => \'ASC\' ) );
if ( empty( $categories ) ) {
// If no terms are assigned to this post, use a string instead (can\'t leave the placeholder there)
$job_listing_category = _x( \'uncategorized\', \'slug\' );
} else {
// Replace the placeholder rewrite tag with the first term\'s slug
$first_term = array_shift( $categories );
$job_listing_category = $first_term->slug;
}
if ( empty( $regions ) ) {
// If no terms are assigned to this post, use a string instead (can\'t leave the placeholder there)
$job_listing_region = _x( \'anywhere\', \'slug\' );
} else {
// Replace the placeholder rewrite tag with the first term\'s slug
$first_term = array_shift( $regions );
$job_listing_region = $first_term->slug;
}
$find = array(
\'%category%\',
\'%region%\'
);
$replace = array(
$job_listing_category,
$job_listing_region
);
$replace = array_map( \'sanitize_title\', $replace );
$permalink = str_replace( $find, $replace, $permalink );
return $permalink;
}
add_filter( \'post_type_link\', \'job_listing_post_type_link\', 10, 2 );
function change_job_listing_slug( $args ) {
$args[\'rewrite\'][\'slug\'] = \'job/%category%/%region%\';
return $args;
}
add_filter( \'register_post_type_job_listing\', \'change_job_listing_slug\' );
function add_region_endpoint_tag() {
add_rewrite_tag( \'%region%\', \'([^/]*)\' );
}
add_action( \'init\', \'add_region_endpoint_tag\' );
这也正是我所需要的,URL显示为/category/region/name/——然而我的画廊图片和博客帖子都显示为404。
即使包括:
// Abort if post is not a job
if ( $post->post_type !== \'job_listing\' ) {
return $permalink;
}
有谁能帮我一下,我该如何告诉WP Job Manager在修改永久链接时省略博客帖子,我相信这是附件帖子类型?