WP选择其他帖子类型作为父级

时间:2013-08-06 15:39:22

标签: php wordpress rewrite

我想为我的2个自定义帖子类型创建一个很好的可读永久链接结构。第一个CPT“国家”,第二个CPT“地区”。

这是我插入区域的代码

// region options
$region_item = array(
    'post_parent' => get_the_ID(),
    'post_author' => $user->ID,
    'post_title' => $region_name,
    'post_content' => $region_content,
    'post_status' => $post_status,
    'post_type' => 'region'
);

// insert region
$region_item_id = wp_insert_post($region_item);

因此,网址将为:http://www.ex.com/USA/Nevada但是当我调用此网址时,wordpress会显示一个未找到的网页,那么我的问题是如何修复此网址?

1 个答案:

答案 0 :(得分:0)

转到设置 - >永久链接并刷新页面。这会为您刷新重写规则。

此外: 这是register_post_type的一个参数(array()重命名该默认slug(your.com/slug/post-name)可能是一个很好的选择。

    //'rewrite' => false, /* you can specify its url slug */
    'rewrite'   => array( 
        'slug' => 'USA', //a slug used to identify the post type in URLs.
        'with_front' => false,
        'feed'=> true,  
        'pages'=> true 
        ),