Wordpress:保存或编辑帖子时执行功能 [英] Wordpress: executing function when saving or editing post

查看:85
本文介绍了Wordpress:保存或编辑帖子时执行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要完成的工作: 如果要添加或编辑帖子,我想运行一个将post_id,所有自定义字段值和类别ID放入我创建的其他数据库表中的函数. 我只想知道如何执行此函数以及如何获取值.

This is what I'm trying to accomplish: If I'm adding or editing post I want to run a function that puts post_id, all the custom field values and category ids to some other db table I've created. I just want to know how to execute this function and how to get the values.

推荐答案

将以下内容放入主题的functions.php文件中.它将同时保存和更新.由于您拥有职位ID,因此您可以做任何您想做的事情.

Put the following in your functions.php file of your theme. It will run on both save as well as well update. Since you have the post ID, you can do whatever you want.

function do_my_stuff($post_ID)  {
   //do my stuff here;
   return $post_ID;
}

add_action('save_post', 'do_my_stuff');

这篇关于Wordpress:保存或编辑帖子时执行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆