How do I ensure that post_type and Taxonomy use the same slug?

[ad_1]

Hi. I had to create a Custom Post Type and taxonomy to add a question and answer section to my site. But I want both of them to use the same persistent link. The codes are like this, so one of the two doesn’t work, how can I stop them from blocking each other?

The use I want it to be;

Custom Post Tyle: websitename.com/question-answer/question-title

Taxonomi: websitename.com/question-answer/category-name

function post_type_question_answer() {
$args = array(
‘labels’ => $labels,
‘has_archive’ => true,
‘public’ => true,
‘hierarchical’ => false,
‘taxonomies’ => array(
‘question_answer_taxonomi’
),
‘rewrite’ => array(
‘slug’ => ‘question-answer’
),
‘show_in_rest’ => true,
);
register_post_type( ‘question_answer’, $args );
}
add_action( ‘init’, ‘post_type_question_answer’ );

register_taxonomy(‘question_answer_taxonomi’, [‘question_answer’], [
‘hierarchical’ => true,
‘rewrite’ => array(
‘slug’ => ‘question-answer’
)
]);
register_taxonomy_for_object_type(‘question_answer_taxonomi’, ‘question_answer’);

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer