Hi
I want to change the permalink structure like this
https://Example.com/ads/748
https://Example.com/ads/%cpt_id%
======
I used this:
add_action('init', 'vacancies_rewrite');
function vacancies_rewrite() {
global $wp_rewrite;
$queryarg = 'post_type=vacancies&p=';
$wp_rewrite->add_rewrite_tag('%cpt_id%', '([^/]+)', $queryarg);
$wp_rewrite->add_permastruct('vacancies', '/ads/%cpt_id%', false);
}
add_filter('post_type_link', 'vacancies_permalink', 1, 3);
function vacancies_permalink($post_link, $id = 0, $leavename) {
global $wp_rewrite;
$post = &get_post($id);
if ( is_wp_error( $post ) )
return $post;
$newlink = $wp_rewrite->get_extra_permastruct('vacancies');
$newlink = str_replace("%cpt_id%", $post->ID, $newlink);
$newlink = home_url(user_trailingslashit($newlink));
return $newlink;
}
like in above ,the permalink will changed,but when click and go to the that link,the page 404 [Not Found] is shown .
Where of this code should be change?
Please help me for this
Thanks