custom taxonomy - Remove "-2" from a Toolset Types URL with the same post name

admin2025-06-04  2

I'm using Toolset Types to create a custom post type, and within that post type there is a taxonomy. I have created two posts with the same name, but in a different taxonomy.

For the purposes of example:

  • my custom post type is called "food"
  • my taxonomies are called "German" and "English"
  • my post name is "sausage"
  • I want two different posts, one "sausage" within the "German" taxonomy, and one "sausage" within the "English" taxonomy.

At the moment, my "German sausage" post is at the URL: sitename/german/sausage.

My "English sausage" post is at the URL: sitename/english/sausage-2.

Here you can see my problem: the second post with the same name has a -2 tacked on to the end of the URL. My question is, how can I remove this, so that the URL becomes sitename/english/sausage? Technically, this should be possible given the fact that they are in different taxonomies.

If you can explain what needs to be done to me (I'm fairly comfortable with PHP and MySQL), I'm happy to code it myself, although of course I'll be very grateful if you can code a fix yourself. Ideally I won't have to use a workaround such as a rewrite rule or a new post type as well.

Thank you so much for your time and help.

I'm using Toolset Types to create a custom post type, and within that post type there is a taxonomy. I have created two posts with the same name, but in a different taxonomy.

For the purposes of example:

  • my custom post type is called "food"
  • my taxonomies are called "German" and "English"
  • my post name is "sausage"
  • I want two different posts, one "sausage" within the "German" taxonomy, and one "sausage" within the "English" taxonomy.

At the moment, my "German sausage" post is at the URL: sitename/german/sausage.

My "English sausage" post is at the URL: sitename/english/sausage-2.

Here you can see my problem: the second post with the same name has a -2 tacked on to the end of the URL. My question is, how can I remove this, so that the URL becomes sitename/english/sausage? Technically, this should be possible given the fact that they are in different taxonomies.

If you can explain what needs to be done to me (I'm fairly comfortable with PHP and MySQL), I'm happy to code it myself, although of course I'll be very grateful if you can code a fix yourself. Ideally I won't have to use a workaround such as a rewrite rule or a new post type as well.

Thank you so much for your time and help.

Share Improve this question edited Feb 22, 2017 at 18:43 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Feb 22, 2017 at 18:31 user113961user113961 1
  • "sausage" must be unique because it is the post_name (slug) and does not depend on any taxonomy. – Arsalan Mithani Commented Feb 22, 2017 at 19:20
Add a comment  | 

1 Answer 1

Reset to default 0

It can be done by using the request filter. Something like this

 function alter_the_query($request) {
       return array('page' => 1, 'pagename' => null);
 }

 add_filter('request','alter_the_query');

Here it forces display of post 1, though of course you will want to do a query to determine the ID. For that, it might prove easiest to first parse the actual URI (from $_SERVER['REQUEST_URI']) rather than use whatever info. WordPress provides (escaping the query string for security reasons, or using prepare()). Also, you may need some conditionals at the begining so it won't break editing, archive display, etc.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749001746a315519.html

最新回复(0)