WordPress的自定义后动作钩 [英] Wordpress custom post action hook
问题描述
我正在开发一个用于wordpress的插件,我希望每次发布,发布,编辑,删除,取消整理等作业类型的自定义帖子时都触发(基本上是每当有更新时
I'm working on a plugin for wordpress that I would like to fire every time a custom post of the type 'job' is posted, published, edited, trashed, untrashed, etc. (basically whenever there is an update to that post type).
我在查找要调用的正确操作钩子时遇到了一些麻烦。我已经搜索过,根据我的理解,我无法使用例如(publish_post),因为我使用的是自定义帖子类型,因此应该与(publish_job)类似。但是,如果我进入工作类别并在工作类别中发布草稿,这似乎也不适合我。
I'm having a bit of trouble finding the correct action hook to call. I have searched, and from my understanding I can't use for example (publish_post) because I am using a custom post type, so it should be something along the lines of (publish_job). However, that doesn't seem to work for me either, if I go in to the jobs category and publish a draft in the jobs category.
所以,我想我有两个问题:
So, I guess I have two questions:
1)在自定义帖子类型的背景下,我应该使用的正确操作是什么。
1) What is the correct action I should be using in the context of a custom post type.
2)
a。我可以使用某种操作来包含对作业类别的各种更改(即:帖子编辑,发布,取消发布,删除/取消删除等)。
b。如果没有,我将如何为所有可能的操作调用add_action。
2) a. Is there some sort of action that I can use to encompass all sorts of changes to the jobs category (ie: post editing, publishing, unpublishing, trash/untrash, etc). b. If not, how would I go about calling add_action for all of those possible actions.
谢谢!
推荐答案
不确定是否只有一个操作,但是有以下各种操作:
Not sure if there is just one action but here are the various actions:
-
save_post(创建或更新)
save_post (create or update)
wp_delete_post(已删除)
wp_delete_post (deleted)
wp_trash_post(已删除)
wp_trash_post (trashed)
所以您可以执行以下操作:
so you can do something like this:
function my_callback_function() {
if($post->post_type = 'job') {
//do something here
}
}
all_actions = array('save_post','wp_delete_post','wp_trash_post');
foreach ($all_actions as $current_action) {
add_action($current_action, 'my_callback_function');
}
这篇关于WordPress的自定义后动作钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!