Use the get_post_custom function in WordPress development

Source: Internet
Author: User
: This article describes how to use the get_post_custom function in WordPress development. if you are interested in the PHP Tutorial, refer to it. 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”}

The above describes how to use the get_post_custom function in WordPress development, including some content, and hope to help those who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.