Tagged: 

Viewing 1 reply thread
  • Author
    Posts
    • #1728
      kjprince
      Member

      I’ve created a metabox on a CPT that I’ve registered the Piklist way. When I enter text in the metabox and save the post, WP creates a new custom field with the same data. Is this by design?

      A features post type, created using a plugin:

      
      <?php
      /*
      Plugin Name: Features Post Type
      Plugin URI: http://www.kj-prince.com
      Description: Creates a "Features" post-type the Piklist Way
      Version: 0.0.0.1
      Author: KJ Prince
      Author URI: http://kj-prince.com
      Plugin Type: Piklist
      License: GPL2
      */
      
        if (!defined('ABSPATH')) {
            exit;
          }
      
        // Flush rewrite rules for custom post types
      add_action( 'after_switch_theme', 'do_flush_rewrite_rules' );
      
      // Flush your rewrite rules
      function do_flush_rewrite_rules() {
        flush_rewrite_rules();
      }
      
        add_filter('piklist_post_types', 'features_type');
        function features_type($post_types)
        {
          $post_types['features'] = array(
            'labels' => piklist('post_type_labels', 'Features')
            ,'title' => __('Enter a new Feature Title')
            
            ,'page_icon' => plugins_url('piklist/parts/img/piklist-page-icon-32.png')
            ,'supports' => array(
              'title'
              ,'revisions'
              ,'editor'
              ,'author'
              ,'thumbnail'
              ,'custom-fields'
              ,'sticky'
              ,'page-attributes'
            )
            ,'public' => true
            ,'admin_body_class' => array (
              'piklist-demonstration'
              ,'piklist-sample'
            )
            ,'has_archive' => true
            ,'rewrite' => array(
              'slug' => 'features'
            )
            ,'capability_type' => 'post'
            ,'edit_columns' => array(
              'title' => __('Features')
              ,'author' => __('Assigned to')
            )
            ,'hide_meta_box' => array(
              'slug'
              ,'author'
            )
            
          );
          
          return $post_types;
        }
      

      A metabox added to the features post types, created by adding the Piklist > Parts > meta-boxes directory scheme:

      
      <?php 
      /*
      Title: Features Description Metabox
      Post Type: features
      New: true
      */
      
      piklist('field', array(
          'type'        => 'textarea',
          'field'       => 'features_description',
          'label'       => 'Feature Description',
          'description' => 'Snippet for Feature Description',
          'value'       => 'Awesome Feature',
          'help'        => 'I need help too',
          'attributes'  => array(
              'class' => 'text'
               )
      )); 
      

      Now when I enter text into the meta box and save, a new custom field is created with the same name and text, as seen below.

      Is this by design?

    • #1729
      Kevin
      Keymaster

      @kjprince-

      This is expected. The Custom Fields Meta Box is core to WordPress and it will allow you to see any meta field not prefixed with _ (which denotes private). Typically when you are creating your own meta boxes you want to remove this from the page by removing ‘custom-fields’ from ‘supports’ in your post type registration.

      Thanks,

      Kevin

Viewing 1 reply thread
  • You must be logged in to reply to this topic.