Add custom fields and background editing functional area to the article in WordPress, _php tutorial

Source: Internet
Author: User

WordPress in the article to add custom fields and background editing functional area,


Add_post_meta
The Add_post_meta function is a function used in WordPress to add custom field values to an article or page.
The effect of using custom column panels to add custom field values to an article is the same as when writing articles in the article authoring interface.

Add_post_meta function Description
Add a custom field for the article.
Common use is: article views, like buttons, SEO plug-ins and other commonly used plug-in is the use of custom field functions.

Detailed parameters

Add_post_meta ($post _id, $meta _key, $meta _value, $unique);

$post _id
ID value of the article or page to which you want to add a custom field
$meta _key
The key value of the custom field (first name)
$meta _value
Values for custom fields
$unique
If you already have a custom field with the same name, whether to repeat the custom field with duplicate names, true to disallow, false to allow
Function Usage Instance

Add the _postviews custom field for the article with ID 1, with a value of 99add_post_meta (1, "_postviews", "Max"), Var_dump (Get_post_meta (1)); echo "
Add the _postviews custom field to the article with ID 1, a value of 999, and allow repeating custom field names Add_post_meta (1, "_postviews", 999,false); Var_dump (Get_post_meta (1)); Echo
";

Demo Effect:

Array (1) {["_postviews"]=> Array (1) {  [0]=>  string (2) "}}array" (1) {["_postviews"]=> Array (2) {
  [0]=>  String (2) "[1]=>"  string (3) "999"}}//does not allow repeating custom fields of code Add_post_meta (1, "_postviews", "996 ", true); Var_dump (Get_post_meta (1)); echo"
"; Add_post_meta (1," _postviews "," 997 ", true); Var_dump (Get_post_meta (1)); echo"
"; Array (1) {[" _postviews "]=> Array (1) { [0]=> string (3)" 996 "}}array (1) {[" _postviews "]=> Array (1) { [0]=> String (3) "996"}}

Add_meta_box
Add_meta_box is a function of WordPress advanced use, can use this function that means that you have more than an ordinary blogger know the world's attention to the blog program, at least you have spent a lot of time on it. can use it, indicating that you are now tossing a theme of your own, plugins, even in the toss WordPress backstage.
Seems to have been more than enough, let us take an advanced angle to explain how this function is used.

Add_meta_box function Description
The Add_meta_box function is a function that is used to add a set area to a page such as an article editor.

Parameter description

<?php Add_meta_box ($id, $title, $callback, $post _type, $context, $priority, $callback _args);?>

To set the value of an id attribute in an area $id HTML code
Title name in the $title area
$callback Add a display function for the Settings area (callback function)
$post _type appear in the edit page of the post or page
$context set the display location of the area, the main editing area, sidebar, other
$priority setting the priority of the area display
$callback additional parameters accepted by the _args callback function
Working with instances

function Add_xz_box () {//Add functions Add_meta_box (' xz_box_1 ', ' add_meta_box test ', ' xz_box_1 ', ' post ', ' side ', ' High ', array (' str1 ', ' str2 ');};/ /in ' add_meta_boxes ' Mount Add_xz_box function add_action (' add_meta_boxes ', ' Add_xz_box ');  function Xz_box_1 ($post, $boxargs) {//Display the callback function of the Settings area echo "Add_meta_box test";};

Articles you may be interested in:

    • Finishing some of the practical WordPress background mysql operation command
    • About the Bluehost space on the WordPress backstage into English solution
    • Add a code instance to the edit background of WordPress

http://www.bkjia.com/PHPjc/1084594.html www.bkjia.com true http://www.bkjia.com/PHPjc/1084594.html techarticle WordPress To add custom fields and background editing function area, Add_post_meta Add_post_meta function is used in WordPress to add custom field values to the article or page a letter ...

  • Related Article

    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.