Get_post_custom () function use parsing in WordPress development, wordpressgetpost_php Tutorial

Source: Internet
Author: User

Get_post_custom () function use parsing in WordPress development, Wordpressgetpost


As with Get_post_meta (), the custom field used to return the article is worth a function, except that the Get_post_custom () function is simpler to use, and you don't even need to set any parameters if you use it in a loop.

In fact, the basic implementation of the Get_post_custom () function is similar to the Get_post_meta ()

Get_post_custom () use

Get_post_custom ($postid);

Accept only one parameter
$postid article ID;

Example Demo

if (Have_posts ()):  while (Have_posts ()): The_post ();   Var_dump (Get_post_custom ());  Endwhile;   endif

The result of the output is as follows: (if the following fields are 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 (keys) and custom field values, sometimes we need to get these two values separately, so get_post_custom_values and Get_post_custom_ are derived from WordPress. Keys two functions, as for the meaning, I really did not find out how much significance, in addition to the bulk deletion of custom fields when there is a certain use, I really did not think of any place to use, perhaps in a vast CMS theme will have a very heavy cast significance.

Before writing to the Get_post_custom function and the Get_post_meta function, privately think, anyway, custom field related functions are not many, so just tidy up a bit, simply put the custom field related functions are written, of course, does not include some basic implementation code of the function.
The get_post_custom_values is used to get the value of the specified custom field for the current article and is returned as an array.

while (Have_posts ()): The_post ();   Var_dump (get_post_custom_values (' Xzmeta ')); Endwhile;   endif

Will generally return the following results

(If the custom field has settings)

Array (2) {[0]=>string (3) "Xz1" [1]=>string (3) "XZ2"}

Get_post_custom_keys is used to get the key values for all 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 generally obtained:
(If the custom field has settings)

Array (4) {[0]=>string] "_edit_last" [1]=>string (Ten) "_edit_lock" [2]=>string] _thumbnail_id [3]=> String (6) "Xzmeta"}

Articles you may be interested in:

    • Use of PHP functions to get recent articles in WordPress development
    • Introduction to the use of PHP functions for custom menus in WordPress development
    • The PHP function used in WordPress to get the search form is parsed
    • Use the Wp_count_posts function in WordPress to count the number of articles
    • PHP functions for invoking comment templates and looping out comments in WordPress
    • Simple steps to add Google search to WordPress
    • Get_post and get_posts function usage in WordPress development
    • Analysis of Post_class and Get_post_class functions in WordPress
    • Installing Hana FLV player in WordPress with video player plugin
    • A detailed description of the use of classification function wp_list_categories in WordPress
    • The implementation of short code in the development of WordPress and the skill of using related functions

http://www.bkjia.com/PHPjc/1088785.html www.bkjia.com true http://www.bkjia.com/PHPjc/1088785.html techarticle The Get_post_custom () function in WordPress development uses parsing, wordpressgetpost, like Get_post_meta (), the custom field used to return the article is worth a function, but get_post_cu. ..

  • 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.