我创建了一个名为job的自定义帖子类型。帖子是用wp\\u insert\\u post()生成的,效果非常好。我的问题是,这些帖子的永久链接要么是错误的,要么是我自己做错了什么。基本上,帖子会指向以下url:http://myblog.eu/job/1-adjointe-de-direction-ee/ 只有当我转到http://myblog.eu/?job=1-adjointe-de-direction-ee/.
我希望每个帖子都能用正确的永久链接生成。
这是一个随机贴子数组:
[9] => stdClass Object
(
[ID] => 42
[post_author] => 1
[post_date] => 2014-03-02 16:40:23
[post_date_gmt] => 2014-03-02 15:40:23
[post_content] => [reso_job_post id=8]
[post_title] => adjoint(e) de direction, La Ciotat
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => open
[post_password] =>
[post_name] => 8-adjointe-de-direction-la-ciotat
[to_ping] =>
[pinged] =>
[post_modified] => 2014-03-02 16:40:23
[post_modified_gmt] => 2014-03-02 15:40:23
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://myblog.eu/job/8-adjointe-de-direction-la-ciotat/
[menu_order] => 0
[post_type] => job
[post_mime_type] =>
[comment_count] => 0
)
下面是我用来生成帖子的代码,所有变量都设置正确(如上所示):
$new_job_post = array(
\'post_content\' => $job_post_shortcode,
\'post_title\' => $job_post_title,
\'post_status\' => \'publish\',
\'comment_status\' => \'closed\',
\'ping_status\' => \'open\',
\'post_name\' => $job_post_slug,
\'post_type\' => \'job\',
\'comment_count\' => \'0\'
);
wp_insert_post( $new_job_post );
以下是我用来创建自定义帖子类型的代码:
function job_custom_init() {
$labels = array(
\'name\' => \'Jobs\',
\'singular_name\' => \'Job\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New Book\',
\'edit_item\' => \'Edit Job\',
\'new_item\' => \'New Job\',
\'all_items\' => \'All Jobs\',
\'view_item\' => \'View Job\',
\'search_items\' => \'Search Jobs\',
\'not_found\' => \'No jobs found\',
\'not_found_in_trash\' => \'No jobs found in Trash\',
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Jobs\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'job\' ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => 5,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\' ),
\'taxonomies\' => array( \'category\', \'post_tag\' )
);
register_post_type( \'job\', $args );
}
add_action( \'init\', \'job_custom_init\' );
function my_rewrite_flush() {
job_custom_init();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, \'my_rewrite_flush\' );
谢谢你。