WordPress开发中的get_post_custom()函数应用解析

同get_post_meta()一样,用于前往文章的自定义字段值得一个函数,只不过get_post_custom()函数应用起来更简略,假如在循环中应用你甚至不需求设置任何参数。

其实get_post_custom()函数的根底完成与get_post_meta()迥然不同~

get_post_custom()应用

get_post_custom($postid);

只承受一个参数
$postid文章id;

实例演示

 if (have_posts()) :
 
 while (have_posts()) : the_post(); 
  var_dump(get_post_custom());
 
 endwhile; 
 
 endif;

输入的后果如下:(假如如下字段有设置的话)

array(4) {
[“_edit_last”]=>
array(1) {
[0]=>
string(1) “1”
}
[“_edit_lock”]=>
array(1) {
[0]=>
string(12) “1342451729:1”
}
[“_thumbnail_id”]=>
array(1) {
[0]=>
string(3) “228”
}
[“xzmeta”]=>
array(2) {
[0]=>
string(3) “xz1”
[1]=>
string(3) “xz2”
}
}

get_post_custom_values和get_post_custom_keys

由于自定义字段分为,键值(keys) 和 自定义字段值(values),有些时分咱们需求独自获取这两个值,所以 WordPress 中就派生出了get_post_custom_values和get_post_custom_keys两个函数,至于意义嘛,我还真没有发现出有多粗心义,除了在批量删除自定义字段的时分有肯定用除外,我还真没想出什么中央能用到,兴许在一个浩瀚的 CMS主题中会有着十分剧组轻重的意义。

之前写到了get_post_custom函数和get_post_meta函数,私下里想着,反正自定义字段的相干函数也不多,所以就随手整顿了一下,索性把自定义字段相干的函数都写一下,当然不包括函数的一些根底完成代码。
get_post_custom_values用于获取以后文章的指定自定义字段的值,并以数组方式前往。

 while (have_posts()) : the_post(); 
  var_dump(get_post_custom_values(‘xzmeta'));
 endwhile; 
 
 endif;

大抵会前往如下后果

(假如自定义字段有设置)

array(2) {
[0]=>
string(3) “xz1”
[1]=>
string(3) “xz2”
}

get_post_custom_keys用于获取以后文章一切的自定义字段的键值。

 if (have_posts()) :
 while (have_posts()) : the_post(); 
  var_dump(get_post_custom_keys());
 endwhile; 
 endif;

大抵会取得 以下后果:
(假如自定义字段有设置)

array(4) {
[0]=>
string(10) “_edit_last”
[1]=>
string(10) “_edit_lock”
[2]=>
string(13) “_thumbnail_id”
[3]=>
string(6) “xzmeta”
}

以上就是安达网络工作室关于《WordPress开发中的get_post_custom()函数使用解析》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: WordPress 字段 PHP PHP编程
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
WordPress中设置Post Type自定义文章类型的实例教程

什么是自定义post? 不要想当然的以为这里的post就是就是指博客中的文章,它只不过是一个文章类的代理词...

WordPress中重置文章循环的rewind_posts()函数解说

有些时分,在索引页中(首页、分类文章、标签文章、作者文章索引……)提行进入 WordPress 文章循环中( Lo...

WordPress博客防黑根底技巧

  依据最新音讯,到了2014年病毒增长规模初次成为近年来的高点,这阐明如今的网络平安并没有设想中那么强...

WordPress建站有哪些劣势

  你还没决议应用什么软件来构建你的新公司网站吗? 依然以为WordPress只是搭建博客吗? 在互联网上有大约2...

php-cgi过程cpu负载过高:禁用wordpress定时义务wp-cron.php

一、成绩形容 1、19号手动晋级到wordpress4.1,21号早上7点看网站php探针,发现零碎负载过高,差不多在1到1...

优化WordPress的Google字体以减速国际效劳器上的运转

因为Google被彻底墙掉,不翻墙就无奈加载谷歌字体。很多老手冤家常常埋怨本人买的主机如何如何慢,给的示例...

需求提交

客服服务

亿鸽在线客服系统