No plug-in for custom data input in the wordpress background

Source: Internet
Author: User
Tags php foreach
CMS can always make people crazy, too messy, but it also has its own rules. This article mainly solves the problem: when you add an article or page, you find that the original blog system does not meet your requirements. You need to add fields or add tables, you don't want to use plug-ins. At this time, I believe this blog will be of great help to you. To implement me

CMS can always make people crazy, too messy, but it also has its own rules. This article mainly solves the problem: when you add an article or page, you find that the original blog system does not meet your requirements. You need to add fields or add tables, you don't want to use plug-ins. At this time, I believe this blog will be of great help to you. To implement me

CMS can always make people crazy, too messy, but it also has its own rules. This article mainly solves the following problems:

When you add an article or page, you find that the original blog system does not meet your requirements. To add a field or add a table, you do not want to use a plug-in. At this time, I believe this blog will be of great help to you.

To implement the functions I mentioned, four files must be changed. There is no problem with 3.4 and 3.5. I have not tried other versions.

 /wp-admin/edit-form-advanced.php /wp-admin/includes/meta-boxes.php /wp-admin/includes/post.php /wp-includes/post.php

1. register the data block we want to add. Modify the/wp-uplodes/post. php file

Function create_initial_post_types () {register_post_type ('post', array ('labels' => array ('name _ admin_bar '=> _ x ('post ', 'Add new on admin bar'),), 'public' => true, '_ builtin' => true,/* internal use only. don't use this when registering your own post type. */'_ edit_link' => 'post. php? Post = % d',/* internal use only. don't use this when registering your own post type. */'capability _ type' => 'post', 'map _ meta_cap '=> true, 'hierarchical' => false, 'rewrite' => false, 'query _ var' => false, 'delete _ with_user '=> true, 'supports' => array ('title ',............., 'refreshs', 'post-formats', 'product-category '), // product-category custom module ));............................. ............

AboveProduct-categoryI added a module and checked the code carefully. It feels a bit like authorization.

2. Create the product-category data module. Modify/wp-admin/DES/meta-boxes.php

/*** Add by tank * Display product category attributes form fields. ** @ since 2.7.0 ** @ param object $ post */function product_category_meta_box ($ post) {$ product_father = 5; $ child_page = wp_get_pages ("sort_order = desc & title_li = & child_of = ". $ product_father );
 
 
    $ V):?>
  • ....................

Three, the data module is ready to send, to/wp-admin/edit-form-advanced.php call

if ( post_type_supports($post_type, 'product-category') )    add_meta_box('pageproductcategory', 'post' == $post_type ? __('Product Category') : __('Attributes'), 'product_category_meta_box', null, 'side', 'core');

Explanation:

1. The product-category is/wp-schemdes/post. php file to add the module name.

2. pageproductcategory is the id of p in html. It can be customized, but it does not need to be duplicated by other modules.

3, 'post' = $ post_type, determine whether it is post, because I added the product-category in post. 'Product Category 'label name.

4, product_category_meta_box, is the method name customized in/wp-admin/categordes/meta-boxes.php.

4. Data warehouse receiving, modify/wp-admin/schemdes/post. php

function edit_post( $post_data = null ) {。。。。。。。。。。。。。。。。。。。。。    if ( 'post' == $post_data['post_type'] ){        if(!empty($post_data['product_category'])){            update_post_meta( $post_ID, '_product_category_for_flow', implode(',',$post_data['product_category']));        }    }。。。。。。。。。。。。。。。。。。。。。。}

Add the above Code in the edit_post method. Here, it just means to put the data in the post_meta table.

Add a custom module to the wordpress background

Add to favorites and share this article!

CMS can always make people crazy, too messy, but it also has its own rules. This article mainly solves the problem: when you add an article or page, you find that the original blog system does not meet your requirements. You need to add fields or add tables, you don't want to use plug-ins. At this time, I believe this blog will be of great help to you. To implement the functions I mentioned, four files must be changed. There is no problem with 3.4 and 3.5. I have not tried other versions. /Wp-admin/edit-form-advanced.php/wp-admin/prodes/meta-boxes.php/wp-admin/prodes/post. php/wp-uplodes/post. php 1: register the data block we want to add. Modify/wp-uplodes/post. PHP file function create_initial_post_types () {register_post_type ('post', array ('labels' => array ('name _ admin_bar '=> _ x ('post ', 'Add new on admin bar'),), [...]

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.