如果你每篇文章或页面都需要插入同一个自定义字段和值,可以考虑在WordPress发布文章/页面时,自动添加默认的自定义字段。将下面的代码添加到当前主题的 functions.php 即可:

1
2
3
4
5
6
7
8
9
10
11
12
/**
* WordPress发布文章/页面时自动添加默认的自定义字段
* https://www.wpdaxue.com/add-custom-field-automatically-post-page-publish.html
*/
add_action('publish_page', 'add_custom_field_automatically');//发布页面时
add_action('publish_post', 'add_custom_field_automatically');//发布文章时
function add_custom_field_automatically($post_ID) {
global $wpdb;
if(!wp_is_post_revision($post_ID)) {
add_post_meta($post_ID, '字段名', '字段值', true);
}
}

注:根据自己的需要,修改第 10 行的字段名和字段值。也可以修改 5、6 行决定是发布文章还是页面才添加。

最新文章

  1. Android学习---如何创建数据库,SQLite(onCreate,onUpgrade方法)和SQLiteStudio的使用
  2. TortoiseSVN 过滤文件(包括已提交和未提交)
  3. poj3692 最大点权独立集/最大独立集
  4. VB6 GDI+ 入门教程[8] Bitmap魔法(1):创建
  5. Apriori算法实例----Weka,R, Using Weka in my javacode
  6. XFS文件系统功能解析
  7. HBase API详解
  8. 设计模式六大原则-OCP
  9. projecteuler---->problem=14----Longest Collatz sequence
  10. Hibernate进化史-------Hibernate概要
  11. C++一些注意点之转换操作符
  12. [原创]JS实现数据筛选(each)
  13. Linux指令--which,whereis,locate,find
  14. Oracle 11g R2性能优化 10046 event
  15. Appium 框架工作流程及原理
  16. exl表格找两个字符间的数据
  17. 【转】C++拷贝构造函数详解
  18. ubuntu 安装source insight3.5
  19. PAT (Advanced Level) Practise 1002 解题报告
  20. 转载:centos安装redis

热门文章

  1. Linux基础:Day03
  2. 在写微信小程序如何 首次编译的是当前写的页面
  3. kepp running 团队视频分析初步总结
  4. Java第二十二天,异常
  5. C语言 文件操作(六)
  6. TP的where方法的使用
  7. vue中axios的安装使用
  8. [转] [腾讯游戏学院] Roguelike到底是什么?
  9. AJ学IOS 之ipad开发Popover的调色板应用_popover显示后其他控件仍然能进行交互
  10. AJ学IOS(37)UI之CALayer