Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add custom fields and background editing function areas to articles in WordPress

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to add custom fields and background editing function areas to articles in WordPress. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

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 using the custom column panel to add custom field values to the article in the article writing interface.

Add_post_meta function description

Add custom fields to the story.

Common uses are: article browsing times, like buttons, seo plug-ins and other common plug-ins are the custom field functions used.

Detailed explanation of parameters

Add_post_meta ($post_id, $meta_key, $meta_value,$unique)

$post_id

The ID value of the article or page to which you want to add a custom field

$meta_key

Key value (first name) of the custom field

$meta_value

Value of a custom field

$unique

If you already have a custom field with the same name, whether to add a custom field with the same name repeatedly. It is not allowed for true and allowed for false.

Examples of function usage

/ / add a _ postviews custom field for articles with ID 1, with a value of 99add_post_meta (1, "_ postviews", "99"); var_dump (get_post_meta (1)); echo ""; / / add a postviews custom field with a value of 999 for articles with ID 1, and allow repetition of custom field names add_post_meta (1, "_ postviews", 999false); 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"}} / / it is not allowed to repeat the custom field 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 an advanced function used by WordPress, which means you already know more about this world-famous blogger than the average blogger, or at least you've spent a lot of time on it. Being able to use it means that you are now messing with your own theme, plugin, or even WordPress background.

It seems that enough has been said, so let's explain how to use this function from an advanced point of view.

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

The value of the id property in the setting area in the $id HTML code

Title name in the $title area

The display function of the setting area added by $callback (callback function)

$post_type is displayed on the edit page of post or page

Display location of $context setting area, main editing area, sidebar, etc.

$priority sets the priority of the area display

Additional parameters accepted by the $callback_args callback function

Use an example

Function add_xz_box () {/ / add the function add_meta_box ('xz_box_1',' add_meta_box test', 'xz_box_1','post','side','high',array (' str1','str2'));}; / / mount the add_xz_box function add_action ('add_meta_boxes','add_xz_box') in' add_meta_boxes' Function xz_box_1 ($post,$boxargs) {/ / shows the callback function echo "add_meta_box Test" in the settings area;}; Thank you for reading! On "how to add custom fields and background editing functional areas to the article in WordPress" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development