来自自定义帖子类型wordpress的元字段的永久链接

来自自定义帖子类型wordpress的元字段的永久链接,wordpress,custom-post-type,permalinks,Wordpress,Custom Post Type,Permalinks,我的wordpress实例中有5个自定义字段,它们是布尔真/假值 物业类型投资、物业类型办公室、物业类型租赁、物业类型工业、物业类型土地 是否有可能为这个自定义帖子类型创建一个永久链接,以检查每个元值是否为真——如果是这样的话,将一个值附加到带有连字符的url 示例:如果属性类型投资、属性类型办公室和属性类型土地为true。我希望永久链接是 /挂牌/投资办公室土地/职务/ 这是我的挂号信类型 register_post_type( 'properties', array(

我的wordpress实例中有5个自定义字段,它们是布尔真/假值

物业类型投资、物业类型办公室、物业类型租赁、物业类型工业、物业类型土地

是否有可能为这个自定义帖子类型创建一个永久链接,以检查每个元值是否为真——如果是这样的话,将一个值附加到带有连字符的url

示例:如果属性类型投资、属性类型办公室和属性类型土地为true。我希望永久链接是

/挂牌/投资办公室土地/职务/

这是我的挂号信类型

register_post_type( 'properties',
    array(
        'labels' => array(
            'name' => 'Properties',
            'singular_name' => 'Property',
            'add_new' => 'Add New',
            'add_new_item' => 'Add New Property',
            'edit' => 'Edit',
            'edit_item' => 'Edit Property',
            'new_item' => 'New Property',
            'view' => 'View',
            'view_item' => 'View Property',
            'search_items' => 'Search Properties',
            'not_found' => 'No Property found',
            'not_found_in_trash' => 'No Properties found in Trash',
            'parent' => 'Parent Property'
        ),

        'public' => true,
        'rewrite' => array('slug'=>'listings'),
        'menu_position' => 15,
        'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ),
        'taxonomies' => array( '' ),
        'has_archive' => true
    )
);

你可以重写规则

function prefix_investment_rewrite_rule() {
    add_rewrite_rule( 'listings/([^/]+)/investment-office-land', 'index.php?listings=$matches[1]&investment-office-land=yes', 'top' );
}

add_action( 'init', 'prefix_investment_rewrite_rule' );

//You should register the query var
function prefix_register_query_var( $vars ) {
    $vars[] = 'investment-office-land';
    return $vars;
}

add_filter( 'query_vars', 'prefix_register_query_var' );

// assign a template
function prefix_url_rewrite_templates() {
     if ( get_query_var( 'investment-office-land' ) && is_singular( 'listings' ) ) {
        add_filter( 'template_include', function() {
            return get_template_directory() . '/single-listings-investment-office-land.php';
        });
    }
}

add_action( 'template_redirect', 'prefix_url_rewrite_templates' );
不要忘记在register\u post\u类型之后刷新重写规则

flush_rewrite_rules();  

您可以通过在管理面板->设置->永久链接->自定义结构中使用
/%category%/%postname%/
的简单方法来测试使用

谢谢你的回复。。。看起来这个解决方案只适用于投资办公室土地组合。我需要它能够解决所有可能的组合的基础上,这5个领域我列出。示例:/investment/,/office-rental/,/investment-office-rental-land-industrial/,等等……您能检查一下吗。这深刻地解释了我上面所写的一切。