このコードで修正されました。
/**
* Re-write post type urls
*/
function rewrite_post_type_init() {
// semua post type
global $wpdb;
$query_type = $wpdb->get_results("
SELECT *
FROM " . $wpdb->prefix . "mf_posttypes
ORDER BY name
ASC
");
// tampilkan post type
foreach ($query_type as $type) {
$args = array(
'label' => __($type->name, 'oelas'),
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'page-attributes'),
'taxonomies' => array(strtolower($type->name).'_brand', 'post_tag'),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'rewrite' => array('slug' => strtolower($type->name)),
);
register_post_type($type->type, $args);
add_rewrite_rule(
'^'.strtolower($type->name).'/([^/]+)/?$',
'index.php?post_type='.$type->type.'&name=$matches[1]',
'top'
);
}
}
add_action('init', 'rewrite_post_type_init');
function rewrite_post_type_flatten_hierarchies($post_link, $post) {
// semua post type
global $wpdb;
$query_type = $wpdb->get_results("
SELECT *
FROM " . $wpdb->prefix . "mf_posttypes
ORDER BY name
ASC
");
// tampilkan post type
foreach ($query_type as $type) {
if (strtolower($type->name) != $post->post_type) {
return $post_link;
}
$uri = '';
foreach ($post->ancestors as $parent) {
$uri = get_post($parent)->post_name . "/" . $uri;
}
return str_replace($uri, '', $post_link);
}
}
add_filter('post_type_link', 'rewrite_post_type_flatten_hierarchies', 10, 2);
/***************** akhir */
どのようなパラマリンク構造を使用していますか? –
以下のコードで修正されました。 – Opsional