Add a custom field to the article and edit the function area in the background in WordPress. _ PHP Tutorial

Source: Internet
Author: User
Add custom fields and the background editing area to the article in WordPress ,. Add custom fields and the background editing area to the article in WordPress, the add_post_metaadd_post_meta function is a function in WordPress that is used to add custom field values to articles or pages. WordPress adds custom fields to articles and supports background editing,

Add_post_meta
The add_post_meta function is a function used in WordPress to add custom field values to articles or pages,
Its usage is the same as adding custom field values to an article by using the custom column panel on the document writing interface.

Add_post_meta function description
Add custom fields to the document.
Common use: articles browsing times, favorite buttons, seo plug-ins and other commonly used plug-ins are the use of custom field functions.

Parameter details

add_post_meta($post_id, $meta_key, $meta_value,$unique);

$ Post_id
ID of the document or page for which you want to add a custom field
$ Meta_key
Key Value (name) of the custom field)
$ Meta_value
Custom field value
$ Unique
If a user-defined field with the same name already exists and whether to add a user-defined field with the same name again, true is not allowed, false is allowed
Function instance

// Add the _ postviews custom field to an article with ID 1. The value is 99add_post_meta (1, "_ postviews", "99"); var_dump (get_post_meta (1 )); echo"
"; // Add a _ postviews custom field to an article with ID 1. The value is 999, and the custom field name add_post_meta (1," _ postviews ", 999, false); var_dump (get_post_meta (1); echo"
";

Demo effect:

Array (1) {["_ postviews"] => array (1) {[0] => string (2) "99"} array (1) {["_ postviews"] => array (2) {[0] => string (2) "99" [1] => string (3) "999" }}// code that does not allow repeated custom fields 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 an advanced function used by WordPress. if you can use this function, you are more familiar with this world-renowned blog program than an ordinary blogger, at least you have spent a lot of effort on it. It can be used to show that you are currently tossing your own theme, plug-in, or even tossing the WordPress background.
It seems that we have already described enough. next we will explain how to use this function from an advanced perspective.

Add_meta_box function description
The add_meta_box function is a function used to add a set region on the document editing page.

Parameter description

<?php add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args ); ?>

$ Id: Set the id attribute value in the region in the HTML code.
$ Title name in the title area
$ Callback: Display function of the setting area added (callback function)
$ Post_type is displayed on the post or page editing page.
$ Context: Set the display position of the region, including the main editing area, sidebar, and others.
$ Priority: set the priority of the region display.
$ Callback_args: Additional parameters accepted by the callback function
Use instance

Function add_xz_box () {// add the add_meta_box ('xz _ box_1 ', 'Add _ meta_box test', 'xz _ box_1', 'post ', 'Day', 'high', array ('str1', 'str2 '));}; // Mount add_xz_box function add_action ('add _ meta_boxes ', 'Add _ xz_box') on 'Add _ meta_boxes '; function xz_box_1 ($ post, $ boxargs) {// display the callback function echo "add_meta_box test ";};

Articles you may be interested in:
  • Some practical WordPress MySQL Operation Commands
  • Solutions for turning wordpress background into English on bluehost space
  • Add code instances in the prompt box to the WordPress editing background

Using, add_post_meta the add_post_meta function is a function used in WordPress to add custom field values to articles or pages...

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.