CPT UI change custom taxonomy url

I have created new post type "groceries" and created "fruit" taxonomiy and added bunch of category b

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745234981a4617849.html

相关推荐

  • CPT UI change custom taxonomy url

    I have created new post type "groceries" and created "fruit" taxonomiy and added bunch of category b

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信