In WordPress development, the get_post_custom () function is parsed and wordpressgetpost is used. In WordPress development, the get_post_custom () function is parsed. wordpressgetpost is the same as get_post_meta (). the custom field used to return the article is worth a function, except that the get_post_custom () function in WordPress development is parsed, wordpressgetpost
Like get_post_meta (), the custom field used to return the article is worth a function, but the get_post_custom () function is easier to use. if you use it in a loop, you do not even need to set any parameters.
In fact, the basic implementation of the get_post_custom () function is similar to that of the get_post_meta () function ~
Use get_post_custom ()
get_post_custom($postid);
Only one parameter is accepted.
$ Postid document id;
Instance demo
if (have_posts()) : while (have_posts()) : the_post(); var_dump(get_post_custom()); endwhile; endif;
The output result is as follows: (if the following field is set)
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 and get_post_custom_keys
Because custom fields are divided into key values and value values, sometimes we need to obtain these two values separately, therefore, the get_post_custom_values and get_post_custom_keys functions are derived from WordPress. As for the meaning, I have not found much significance, except for some usage when deleting custom fields in batches, I really didn't come up with anything to use, maybe it would be of great significance in a vast CMS topic.
Previously, I wrote the get_post_custom function and the get_post_meta function. I thought that there are not many related functions for custom fields, so I just sorted them out, simply write all the functions related to the custom field, excluding some basic implementation code of the function.
Get_post_custom_values is used to obtain the value of a specified custom field in the current article and return it in an array.
while (have_posts()) : the_post(); var_dump(get_post_custom_values(‘xzmeta')); endwhile; endif;
The following results are returned.
(If the custom field is set)
array(2) {[0]=>string(3) “xz1”[1]=>string(3) “xz2”}
Get_post_custom_keys is used to obtain the key values of all the custom fields in the current article.
if (have_posts()) : while (have_posts()) : the_post(); var_dump(get_post_custom_keys()); endwhile; endif;
The following results are obtained:
(If the custom field is set)
array(4) {[0]=>string(10) “_edit_last”[1]=>string(10) “_edit_lock”[2]=>string(13) “_thumbnail_id”[3]=>string(6) “xzmeta”}
Articles you may be interested in:
- Analysis of PHP functions used for obtaining recent articles in WordPress development
- Introduction to using custom menu related PHP functions in WordPress development
- Use of PHP functions used to retrieve search forms in WordPress
- Use the wp_count_posts function in WordPress to count the number of articles
- Detailed description of PHP functions that call comment templates and output comments cyclically in WordPress
- Simple steps to add the Google search function to WordPress
- Details on the use of the get_post and get_posts functions in WordPress development
- Parse post_class and get_post_class functions in WordPress
- Install and use the video Player plug-in Hana Flv Player in WordPress
- The use of the wp_list_categories function in WordPress
- Implementation of short code in WordPress development and related function usage skills
The Parse () function uses parsing. wordpressgetpost is the same as get_post_meta (). the custom field used to return the article is worth a function, except get_post_cu...