Tagged: 

Viewing 7 reply threads
  • Author
    Posts
    • #4177
      vagelis
      Member

      Hi. I’ve recently made a plugin using piklist to register a custom post type and added some metaboxes to it. The problem is that each field in metabox appears many times and when I try to save a value it’s showing on the other fields too. Apart from that it only saves as draft and cannot be published. I’ve attached some screenshots.

      Attachments:
      You must be logged in to view attached files.
    • #4180
      Steve
      Keymaster

      @vagelis– Happy to help. Can you post your field code here so we can take a look? Or email the plugin to [email protected]

    • #4181
      vagelis
      Member

      Thank you for the quick reply and sorry for not posting these before.

      This is my post type snippet:

      function boats_post_types($post_types) {
      
      $post_types['boats'] = array(
            'labels' 			=> piklist('post_type_labels', 'Boats')
            ,'title' 			=> __('Add a new Boat')
      
            ,'supports' 		=> array(
              'title',
              'revisions',
            )
            ,'public' 		=> true
      
            ,'taxonomies'		=> array('category')
      
            ,'has_archive'	=> true
            ,'rewrite' 		=> array(
              'slug' 			=> 'boat'
            )
            ,'edit_columns' 	=> array(
              'title' 		=> __('Boat')
      		,'post_states' 	=> __('Status')
            )
            ,'hide_meta_box' 	=> array(
              'slug'
              ,'author'
            )
            ,'post_states' 	=> true
            ,'status' 		=> array(
              'draft' 		=> array(
                'label' 		=> 'Inactive',
                'public' 	=> true
              ),
              'active' 		=> array(
                'label' 		=> 'Active',
                'public' 	=> true
              ),
              'published'   => array(
                'label'     => 'Published',
                'public'    => true
              )
            )
          );
      
          return $post_types;
      }
      
      add_filter('piklist_post_types', 'boats_post_types');
      
      function boats_rewrite_flush() {
      
          // codex_boats_init();
      
          boats_post_types();
      
          flush_rewrite_rules();
      }
      
      register_activation_hook( __FILE__, 'boats_rewrite_flush' );

      and my metabox snippet:

      <?php
      /*
      Title: Test
      Description: Test metabox
      Post Type: boats
      Context: normal
      Priority: high
      Locked: false
      Collapse: true
      */
      
      piklist('field', array(
       'type' => 'text'
       ,'field' => 'field_name'
       ,'label' => 'Sellers Name'
       ,'description' => 'Put sellers name here.'
       ,'attributes' => array(
         'class' => 'text'
       )
       ));
      
      piklist('field', array(
       'type' => 'text'
       ,'field' => 'field_name'
       ,'label' => 'Phone'
       ,'description' => 'Put sellers phone here.'
       ,'attributes' => array(
         'class' => 'text'
       )
       ));
      
      piklist('field', array(
       'type' => 'text'
       ,'field' => 'field_name'
       ,'label' => 'Mobile phone'
       ,'description' => 'Put sellers mobile phone here.'
       ,'attributes' => array(
         'class' => 'text'
       )
       ));
      
      piklist('field', array(
       'type' => 'text'
       ,'field' => 'field_name'
       ,'label' => 'Email'
       ,'description' => 'Put sellers email here.'
       ,'attributes' => array(
         'class' => 'text'
       )
       ));
      
      piklist('field', array(
       'type' => 'text'
       ,'field' => 'field_name'
       ,'label' => 'Address'
       ,'description' => 'Put sellers address here.'
       ,'attributes' => array(
         'class' => 'text'
       )
       ));
      
      piklist('field', array(
       'type' => 'text'
       ,'field' => 'field_name'
       ,'label' => 'Boat name'
       ,'description' => "Put boat's name here."
       ,'attributes' => array(
         'class' => 'text'
       )
       ));
    • #4182
      Steve
      Keymaster

      Each field name needs to be unique. This is not a Piklist “thing”, but standard on HTML forms… you can’t have more than one field with the same name.

      Make sure all of these are unique, and the form should work perfectly:
      ,'field' => 'field_name'

      So they should be something like:
      ,'field' => 'vagelis_sellers_name'
      ,'field' => 'vagelis_phone'
      ,'field' => 'vagelis_mobile_phone'

      It’s always a good idea to prepend your field names with some unique so you don’t conflict with other plugins.

    • #4183
      vagelis
      Member

      Thanx you Steve! Rookie mistake. It’s working now. And thank you for your advice. I’ll surely follow it. Another thing happening, is that instead of ‘Publish’ on the right, it says ‘Save’ and after pressing it the post gets published as Draft. How can I change that to show publish(as any other post type) and get publish status instead of draft?

      Attachments:
      You must be logged in to view attached files.
    • #4185
      Steve
      Keymaster

      If you use custom post statuses, then it will say “save”, since you may not be “publishing”.

      Do you need this?

      ,'status' 		=> array(
              'draft' 		=> array(
                'label' 		=> 'Inactive',
                'public' 	=> true
              ),
              'active' 		=> array(
                'label' 		=> 'Active',
                'public' 	=> true
              ),
              'published'   => array(
                'label'     => 'Published',
                'public'    => true
              )
            )
      
    • #4186
      vagelis
      Member

      Not really, Just used it cause I thought it was essential for the metabox to work, following the documentation. I’ve removed it and all is well! Thanx again Steve for your help!

    • #4187
      Steve
      Keymaster

      Great. Closing Ticket!

Viewing 7 reply threads
  • The topic ‘Double Fields Piklist Metaboxes’ is closed to new replies.