custom permalink category not working error 404

I want the permalink to be of type

/%category%/%postname%/

in custom post.
but I get an error 404.

register type:

function register_brandmayers() {

$labels = array(
‘name’ => ‘brands’,
‘singular_name’ => ‘brand’,
‘add_new’ => ‘add brand’,
‘add_new_item’ => ‘add new brand’,
‘edit_item’ => ‘edit brand’,
‘new_item’ => ‘new brand’,
‘all_items’ => ‘all brands’,
‘menu_name’ => ‘brand’
);
$args = array(
‘labels’ => $labels,
‘public’ => true,
‘menu_icon’ => ‘dashicons-media-document’,
‘menu_position’ => 5,
‘has_archive’ => ‘brandmayers’,
‘supports’ => array( ‘title’, ‘excerpt’, ‘thumbnail’, ‘comments’),
‘rewrite’ => array(
‘slug’ => ‘$city’,
‘with_front’ => true,
‘pages’ `enter code here` => true,
‘feeds’ => true,
),
‘capability_type’ => ‘page’,
);
register_post_type(‘brandmayers’,$args);

}

register category:

function taxonomy_for_brandmayers() {
$args = array(
‘label’ => __( ‘citys’, ‘citys’ ),
‘public’ => true,
‘rewrite’ => array(‘slug’ => ‘city’),
‘hierarchical’ => true,

);
register_taxonomy( ‘citys’, ‘brandmayers’, $args );

}
add_action( ‘init’, ‘taxonomy_for_brandmayers’, 0 );

filter:

function wpa_brand_post_link( $post_link, $id = 0 ){
$post = get_post($id);
if ( is_object( $post ) ){
$terms = wp_get_object_terms( $post->ID, ‘citys’ );
if( $terms ){
return str_replace( ‘$city’ , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( ‘post_type_link’, ‘wpa_brand_post_link’, 1, 10 );

but if i follow the link

/brandmayers/%postname%/

it all works

Permalink in wordpress updated

I am programming recently, tell me please where I am wrong

Read more here:: custom permalink category not working error 404

Leave a Reply

Your email address will not be published. Required fields are marked *