admin管理员组

文章数量:1416074

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

Share Improve this question asked Jul 12, 2016 at 20:11 simpletonsimpleton 113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You 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.

本文标签: CPT UI change custom taxonomy url