php - How to get original custom taxonomy slug after the slug has been rewritten?

admin2025-04-21  0

I'm writing ajax handling for a theme. I'm trying to get term and taxonomy slugs from a link I click. The link is being passed with jQuery to PHP for further processing.

Let's say my custom taxonomy is "tax" and term within that taxonomy is "abc":


Example:

link I click looks like this - https://localhost/test/tax/abc/.

It's being parsed with wp_parse_url(). After parsing URL and fiddling with it a little I get "abc" as my term slug and "tax" as my taxonomy slug.

Then I use get_term_by( 'slug', 'abc', 'tax' ) and get term data this way. Simple.


Problem occurs when taxonomy slug is rewritten.

Example 2:

Let's say I've rewritten my custom taxonomy slug "tax" with 'rewrite' => array( 'slug' => 'tax-rewrite' ), passed to register_taxonomy().

Now link I click looks like this: https://localhost/test/tax-rewrite/abc/.

When I pass it to get_term_by() as "tax-rewrite" it fails because get_term_by() needs original taxonomy slug which in this case is still "tax", but I can't get it from the link anymore.

Is there a way to get original taxonomy slug from rewritten link, get original taxonomy slug from rewrite slug, or any other way to get term data for my ajax handling?

Best regards, Dan.

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

最新回复(0)