【问题标题】:WP Choose another post type as parentWP 选择其他帖子类型作为父级
【发布时间】:2013-08-07 00:00:12
【问题描述】:

我想为我的 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);

所以 URL 将是:http://www.ex.com/USA/Nevada 但是当我调用这个 URL 时 wordpress 会显示一个未找到的页面,所以我的问题是如何修复这个 URL?

【问题讨论】:

    标签: php wordpress rewrite


    【解决方案1】:

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

    还有: 这是 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 
            ), 
    

    【讨论】:

    • 可能我没有解释清楚,我使用'More Types'插件在WP中创建其他类型。第一个问题是当我去我在 url index.php?Countries=USA 看到的国家之一时,我需要它像 ex.com/USA 我的第二个问题我需要让这些地区成为像这样的国家的孩子@ 987654322@
    • 您是否在 Settings->permalinks 中指定了永久链接结构?您希望 /%postname%/ 在“自定义”字段中。也试试这个链接[链接]wordpress.org/support/topic/plugin-more-types-permalinks-fix
    • 没有解决我的问题 /?countries=/USA
    • 那么那个插件就废了。我的答案都是正确的。您在插件页面上注意到了吗?!兼容至:3.1.4 上次更新时间:2011-9-3 如果您想要一个快速的使用代码创建 CPT 的速成课程,我可以提供帮助。我已经学会让它变得超级简单。
    • 我现在正在尝试创建一个,如果我遇到任何问题,我会告诉你,谢谢你的帮助
    猜你喜欢
    • 2018-09-24
    • 2014-02-21
    • 1970-01-01
    • 2017-09-19
    • 2016-02-27
    • 2017-07-23
    • 1970-01-01
    • 2015-05-05
    • 2015-11-30
    相关资源
    最近更新 更多