Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 请选择另一个帖子类型作为父类_Php_Wordpress_Rewrite - Fatal编程技术网

Php 请选择另一个帖子类型作为父类

Php 请选择另一个帖子类型作为父类,php,wordpress,rewrite,Php,Wordpress,Rewrite,我想为我的2个自定义帖子类型创建一个可读的permalink结构。第一个CPT“国家”,第二个CPT“区域” 这是我插入区域的代码 // region options $region_item = array( 'post_parent' => get_the_ID(), 'post_author' => $user->ID, 'post_title' => $region_name, 'post_content' => $regio

我想为我的2个自定义帖子类型创建一个可读的permalink结构。第一个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将是:但是当我调用此URL时,wordpress会显示一个未找到的页面,因此我的问题是如何修复此URL?

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

此外: 这是register\u post\u类型(array()的一个参数,用于重命名默认slug(您的.com/slug/post名称)可能是一个很好的选择

    //'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 
        ), 

也许我没有解释清楚,我正在使用“更多类型”插件在WP中创建其他类型。第一个问题是当我去url索引中看到的一个国家时。php?Countries=USA我需要它像我的第二个问题一样,我需要使这些地区成为像这样的国家的子地区。你在设置->per中指定了permalink结构吗malinks?您希望在“自定义”字段中使用/%postname%/。也可以尝试此链接[link]没有解决我的问题/?countries=/us那么这个插件就是废话。我的答案都是正确的。你在插件页面上注意到了吗?!兼容到:3.1.4上次更新:2011-9-3如果你想用我可以帮助的代码快速创建CPT速成班。我已经学会了让它变得超级简单。如果我遇到任何问题,我现在正在尝试创建一个I’我会让你知道的,谢谢你的帮助