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

I'm writing ajax handling for a theme. I'm trying to get term and taxonomy slugs from a link I click. The link

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.

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信