I have created new post type "groceries" and created "fruit" taxonomiy and added bunch of category but when I filter this category url shows like this .localhost/fruit/apple
I'd like show it like .localhost/groceries/fruit/apple
how do I do that i'm using this basic filter:
<li id="categories_topics">
<?php
$args = array(
'show_option_none' => 'Select category',
'taxonomy' => 'fruit',
'field' => 'slug',
'id' => 'cat',
);
?>
<?php wp_dropdown_categories( $args ); ?>
<script type="text/javascript">
<!--
var dropdown = document.getElementById("cat");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
var str = $( "#cat option:selected" ).text();
str = str.replace(/\s+/g, '-').toLowerCase();
location.href = "<?php echo esc_url( home_url( '/' ) ); ?>?fruit="+str
}
}
dropdown.onchange = onCatChange;
-->
</script>
</li>
when I go: .localhost/groceries/fruit/apple
it shows 404 but .localhost/fruit/apple
works fine
I have created new post type "groceries" and created "fruit" taxonomiy and added bunch of category but when I filter this category url shows like this .localhost/fruit/apple
I'd like show it like .localhost/groceries/fruit/apple
how do I do that i'm using this basic filter:
<li id="categories_topics">
<?php
$args = array(
'show_option_none' => 'Select category',
'taxonomy' => 'fruit',
'field' => 'slug',
'id' => 'cat',
);
?>
<?php wp_dropdown_categories( $args ); ?>
<script type="text/javascript">
<!--
var dropdown = document.getElementById("cat");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
var str = $( "#cat option:selected" ).text();
str = str.replace(/\s+/g, '-').toLowerCase();
location.href = "<?php echo esc_url( home_url( '/' ) ); ?>?fruit="+str
}
}
dropdown.onchange = onCatChange;
-->
</script>
</li>
when I go: .localhost/groceries/fruit/apple
it shows 404 but .localhost/fruit/apple
works fine
1 Answer
Reset to default 1You need to do this when you register your taxonomy in register_taxonomy()
Pass the rewrite argument and customize to your needs:
'rewrite' => array('slug' => 'groceries/fruit', 'with_front' => false)
You'll probably need to flush your permalinks in Settings as well.