admin管理员组文章数量:1130349
I want to run some code after a product category is deleted, in that function I want to access the name of the deleted category, and according to their docs I could do this:
add_action('delete_product_cat', 'sync_cat_delete', 10, 1);
function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
var_dump($deleted_term);
}
But when I do it, I get 500 internal server error
So what could be the issue?
Thanks
I want to run some code after a product category is deleted, in that function I want to access the name of the deleted category, and according to their docs I could do this:
add_action('delete_product_cat', 'sync_cat_delete', 10, 1);
function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
var_dump($deleted_term);
}
But when I do it, I get 500 internal server error
So what could be the issue?
Thanks
Share Improve this question asked Dec 31, 2018 at 16:16 AL-KatebAL-Kateb 1033 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 1You get 500 error, because you’ve added your filter incorrectly... It takes 4 params, but you register it as it was using only one.
add_action('delete_product_cat', 'sync_cat_delete', 10, 1);
// 10 is priority, 1 is number of params to take
function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
var_dump($deleted_term);
}
So if you change that 1 to 4, it should be OK.
I want to run some code after a product category is deleted, in that function I want to access the name of the deleted category, and according to their docs I could do this:
add_action('delete_product_cat', 'sync_cat_delete', 10, 1);
function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
var_dump($deleted_term);
}
But when I do it, I get 500 internal server error
So what could be the issue?
Thanks
I want to run some code after a product category is deleted, in that function I want to access the name of the deleted category, and according to their docs I could do this:
add_action('delete_product_cat', 'sync_cat_delete', 10, 1);
function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
var_dump($deleted_term);
}
But when I do it, I get 500 internal server error
So what could be the issue?
Thanks
Share Improve this question asked Dec 31, 2018 at 16:16 AL-KatebAL-Kateb 1033 bronze badges 6- where exactly would this be displaying? – rudtek Commented Dec 31, 2018 at 16:22
- It would be displayed in the ajax response when a category is deleted, I placed var_dump there just for testing purposes, I could read the output with fiddler, an HTTP debugger. – AL-Kateb Commented Dec 31, 2018 at 16:30
-
1
I think your
add_actioncall specifies only a single function parameter (1) but your function actually takes 4 parameters – Tom J Nowell ♦ Commented Dec 31, 2018 at 17:00 - @TomJNowell I figured that much, but according to the docs developer.wordpress/reference/hooks/delete_taxonomy there should be 4 parameters. – AL-Kateb Commented Dec 31, 2018 at 19:01
-
1
So you need to change the number of parameters to
4, not1in youradd_action(). – Jacob Peattie Commented Jan 1, 2019 at 1:55
1 Answer
Reset to default 1You get 500 error, because you’ve added your filter incorrectly... It takes 4 params, but you register it as it was using only one.
add_action('delete_product_cat', 'sync_cat_delete', 10, 1);
// 10 is priority, 1 is number of params to take
function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
var_dump($deleted_term);
}
So if you change that 1 to 4, it should be OK.
本文标签: categoriesHow to access deleted term inside deleteproductcat action
版权声明:本文标题:categories - How to access deleted term inside delete_product_cat action 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749054846a2309182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


add_actioncall specifies only a single function parameter (1) but your function actually takes 4 parameters – Tom J Nowell ♦ Commented Dec 31, 2018 at 17:004, not1in youradd_action(). – Jacob Peattie Commented Jan 1, 2019 at 1:55