Analysis of get_post_custom() function usage in WordPress development, wordpressgetpost_PHP tutorial

WBOY
Release: 2016-07-12 09:01:34
Original
957 people have browsed it

The get_post_custom() function in WordPress development uses parsing. wordpressgetpost

is the same as get_post_meta(). The custom field used to return the article deserves a function, except get_post_custom() Functions are simpler to use and you don't even need to set any parameters if used in a loop.

In fact, the basic implementation of the get_post_custom() function is similar to get_post_meta()~

get_post_custom() uses

get_post_custom($postid);
Copy after login

Accepts only one parameter
$postid article id;

Example demonstration

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

The output results are 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”
}
}

Copy after login

get_post_custom_values ​​and get_post_custom_keys

Because custom fields are divided into keys and values, sometimes we need to obtain these two values ​​separately, so WordPress has derived two functions: get_post_custom_values ​​and get_post_custom_keys. As for As for the meaning, I really haven’t found much significance. Except for its use when deleting custom fields in batches, I really can’t think of any place where it can be used. Maybe it will be very useful in a vast CMS theme. The importance of the crew.

I wrote about the get_post_custom function and get_post_meta function before. I thought privately that there are not many functions related to custom fields anyway, so I sorted it out and simply wrote down all the functions related to custom fields, excluding of course Some basic implementation codes of the function.
get_post_custom_values ​​is used to get the value of the specified custom field of the current article and returns it in the form of an array.

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

The following results will be returned roughly

(if the custom field is set)

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

Copy after login

get_post_custom_keys is used to get the key values ​​of all custom fields in the current article.

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

You will roughly get the following results:
(If custom fields are set)

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

Copy after login

Articles you may be interested in:

  • Analysis of the use of PHP functions used to obtain recent articles in WordPress development
  • Introduction to the use of PHP functions related to custom menus in WordPress development
  • Usage analysis of the PHP function used to obtain the search form in WordPress
  • Use the wp_count_posts function in WordPress to count the number of articles
  • Detailed explanation of calling comment templates and looping output comments in WordPress PHP function
  • Explanation of simple steps to add Google search function in WordPress
  • Detailed explanation of get_post and get_posts functions in WordPress development Using
  • Analysis of post_class and get_post_class functions in WordPress
  • Install and use the video player plug-in Hana Flv Player in WordPress
  • Detailed explanation of the use of the classification function wp_list_categories in WordPress
  • Implementation of short codes in WordPress development and related function usage skills

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1088785.htmlTechArticleThe get_post_custom() function in WordPress development uses parsing. WordPressgetpost is the same as get_post_meta(), which is used to return the post’s auto-data. Defining fields deserves a function, just get_post_cu...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!