Tagged: , ,

Viewing 3 reply threads
  • Author
    Posts
    • #2205
      tuckerjoenz
      Member

      Ok, I’m searching to find out what is causing this and don’t see why it would multiply the fields after I save. When I go to fill out a new “Partner” the fields are fine. Then when I save it get multiple fields. Here is a screen shot:

      Here is how it looks before I fill anything out:

      Here is the code:

      functions.php

      add_filter('piklist_post_types', 'partners_post_type');
       function partners_post_type($post_types)
       {
        $post_types['partners'] = array(
          'labels' => piklist('post_type_labels', 'Partners')
          ,'title' => __('Partners')
          ,'public' => true
          ,'rewrite' => array(
            'slug' => 'partners'
          )
          ,'supports' => array(
            'author'
            ,'revisions'
            ,'title'
          )
          ,'hide_meta_box' => array(
            'slug'
            ,'author'
            ,'revisions'
            ,'comments'
            ,'commentstatus'
          )
        );
      return $post_types;
      }
      add_action( 'save_post', 'partners_post_type' );

      partners.php

      <?php
      /*
      Title: Partners
      Post Type: partners
      Order: 13
      Meta Box: false
      Collapse: false
      */
      ?>
      
      <?php
      
        piklist('field', array(
          'type' => 'file'
          ,'field' => 'upload_basic'
          ,'scope' => 'post_meta'
          ,'label' => __('Partner Logo','piklist-demo')
          ,'options' => array(
            'basic' => true
          )
        ));
      
        piklist('field', array(
          'type' => 'file'
          ,'field' => 'upload_media'
          ,'scope' => 'post_meta'
          ,'label' => __('Media Uploader','piklist-demo')
          ,'description' => __('Validation rule set: Upload no more than two files.','piklist-demo')
          ,'options' => array(
            'modal_title' => __('Add File(s)','piklist-demo')
            ,'button' => __('Add','piklist-demo')
          )
        ));
      
        piklist('field', array(
          'type' => 'text'
          ,'field' => 'text_class_regular'
          ,'label' => 'Partner Name'
          ,'attributes' => array(
            'class' => 'regular-text'
            ,'placeholder' => 'Partner Name'
          )
          ,'on_post_status' => array(
            'value' => 'lock'
          )
        ));
      
        piklist('field', array(
          'type' => 'text'
          ,'field' => 'text_class_regular'
          ,'label' => 'Location'
          ,'attributes' => array(
            'class' => 'regular-text'
            ,'placeholder' => 'Location'
          )
          ,'on_post_status' => array(
            'value' => 'lock'
          )
        ));
      
        piklist('field', array(
          'type' => 'text'
          ,'field' => 'text_class_regular'
          ,'label' => 'Grantee URL'
          ,'attributes' => array(
            'class' => 'regular-text'
            ,'placeholder' => 'http://'
          )
          ,'on_post_status' => array(
            'value' => 'lock'
          )
        ));
      
        piklist('field', array(
          'type' => 'text'
          ,'field' => 'text_class_regular'
          ,'label' => 'Donate URL'
          ,'attributes' => array(
            'class' => 'regular-text'
            ,'placeholder' => 'http://'
          )
          ,'on_post_status' => array(
            'value' => 'lock'
          )
        ));
      
        piklist('field', array(
          'type' => 'editor'
          ,'field' => 'post_content_add_more'
          ,'label' => 'Blurb'
          ,'options' => array (
            'media_buttons' => true
            ,'teeny' => true
            ,'textarea_rows' => 5
            ,'drag_drop_upload' => true
          )
        ));
    • #2206
      Kevin
      Keymaster

      @tuckerjoenz-

      Thats a odd one 🙂 You have two problems with the code you posted.

      1. Remove add_action( ‘save_post’, ‘partners_post_type’ ); from functions.php, you just need add_filter(‘piklist_post_types’, ‘partners_post_type’); to register a new post type.
      2. All of your fields have the same name so you are saving all of the data to one field (‘field’ => ‘text_class_regular’) and then when they render each field pulls that data and displays it, making it appear that it saved multiple times. Always make sure to give unique names to all fields.
    • #2207
      tuckerjoenz
      Member

      @Kevin I could kiss you right now. LOL Thanks and that did the trick. I was confused on those fields thinking that’s what the ‘field’ needed to be set to for that type. Got it now though!

    • #2208
      Kevin
      Keymaster

      HA 🙂 Not a problem, let us know if you need anything else.

Viewing 3 reply threads
  • The topic ‘Fields multiply after save’ is closed to new replies.