Tagged: ,

Viewing 13 reply threads
  • Author
    Posts
    • #7902
      Stephen
      Participant

      Hi, I have a fairly complicated site built atop Piklist. I have been storing repeating groups of (add more) data (in the postmeta table) along with the custom post types I have built. And I need a more reliable way than index to get at these groups for editing and updating. I would have liked to have used grouped fields (serialized in the db), but because my groupings have many conditional values, this won’t currently work in Piklist (see this link).

      So here are my questions to solve this:
      1. Could I store these groups in their own post type and relate them to the parent CPT?
      2. If so, is there a way to allow these child posts to both display AND be editable from within the parent in admin?

      Thanks for any advice or help!

    • #7903
      Dan
      Participant

      Following

    • #7904
      Stephen
      Participant

      I found something in the demo that gets at this idea: /parts/meta-boxes/field-relationship.php

      BUT, I can’t figure out how to add post-meta data to the related post. It will save the title and content shown in the demo, but every time I try to add another field there (for meta-data of the related post) it fails to save into the related post. Is this even possible?

    • #7907
      Stephen
      Participant

      Has anyone done something like this? Does anyone have any example code?

    • #7913

      I see what you’re trying to do and have tried something similar myself (editing a related post meta in the parent) but wasn’t able to do so in any clear or useful way only via piklist.

      I’m also having issues with the conditionals using addmores and nested groups. I’ve just decided to wait until the feature is released (hopefully soon.)

    • #7915
      Stephen
      Participant

      Here is what I have tried/noticed so far. The following code is only a slight change from the demo, but it works/fails in the following ways:

      1. I can relate posts from my CPT “action”, and they will show with the edit box and meta data field.
      2. I can update the regular POST fields like Title and content
      3. I CAN NOT update the associated meta data field (expiration_date). When changed it reverts back to whatever the separate CPT holds.
      4. Changing expiration_date to have a scope of post_meta links it to the parent instead of the child.
      5. Changing scope to the name of my CPT (‘action’) results in nothing working, just blank fields not attached to anything.
      6. I also notice that clicking “save” while in the parent will unfortunately publish instead (I suspect due to the presence on the child post of hidden field with post status of publish, but clearly it should only update the child status, not the parent)
      
       piklist('field', array(
          'type' => 'checkbox'
          ,'field' => '_' . piklist::$prefix . 'relate_post'
          ,'label' => __('Relate Posts', 'my-domain')
          ,'choices' => piklist(
            get_posts(array(
              'post_type' => 'action'
              ,'numberposts' => -1
              ,'orderby' => 'title'
              ,'order' => 'ASC'
            ))
            ,array('ID', 'post_title')
          )
          ,'relate' => array(
            'scope' => 'post'
          )
        ));
      
        $related = get_posts(array(
          'post_type' => 'action'
          ,'posts_per_page' => -1
          ,'post_belongs' => $post->ID
          ,'post_status' => 'publish'
          ,'suppress_filters' => false
        ));
      
      piklist('field', array(
          'type' => 'group'
          ,'scope' => 'post'
          ,'label' => 'Related Posts'
          ,'relate' => array(
            'scope' => 'post'
          )
          ,'add_more'=> true
          ,'fields' => array(
          
          array(
          'type' => 'datepicker'
          ,'field' => 'expiration_date'
          ,'required' => true
          ,'label' => __('Expiration Date', 'my-domain')
          ,'help' => __('Choose an expiration date for this item.', 'my-domain')
          ,'options' => array(
            'dateFormat' => 'yy-mm-dd'
          )
          ,'attributes' => array(
            'size' => 17
          )
        ) 
            ,array(
              'type' => 'text'
              ,'field' => 'post_title'
              ,'label' => 'Post Title'
              ,'columns' => 12
            )
            ,array(
              'type' => 'textarea'
              ,'field' => 'post_content'
              ,'label' => 'Post Content'
              ,'columns' => 12
              ,'attributes' => array(
                'rows' => 5
              )
            )
            ,array(
              'type' => 'hidden'
              ,'field' => 'post_status'
              ,'value' => 'publish'
            )
          )
        ));

      Anyone?

    • #7949
      Stephen
      Participant

      Question for Steve: does the code currently up at github fix these problems? I have been combing through it and see reference in a comment to “Handle relate groups”

    • #7952
      Steve
      Keymaster

      @ssuess– I believe it should. Let us know if you still see issues.

    • #7954
      Stephen
      Participant

      @sbruner – thanks, I will check it out when I get a chance. For the problem above, I ended up having to custom code my own backend ajax related post system, the only parts of piklist in use for that are the postmeta “__relate_post” meta key and the query parameter “post_belongs”, but that should allow me (when all of that is working) to hopefully swap it out. I will let you know what I find.

    • #7956
      Jason
      Keymaster

      Hey @stephen!

      I use relates quite regularly and should work perfectly in the latest RC version. Please grab it from Github and, if you have any issues and are comfortable with Github, please make an issue with any details you can provide. Better yet, as we’re trying to make Piklist core more about community contribution, feel free to make a pull request if you think you’ve found the solution.

    • #8006
      bhushanjawle
      Participant

      Hi @stephen @steve, Just tried release candidate. It does create a new post however post type is set to revision instead of the post_type passed like so

      ,array(
              'type' => 'hidden', 
              'field' => 'post_type', 
              'value' => 'my-custom-type', 
            )
       ,array(
              'type' => 'hidden'
              ,'field' => 'post_status'
              ,'value' => 'publish'
            )
      

      Am I passing the parameter as expected or am I missing something ?
      Thanks

    • #8017
      Steve
      Keymaster

      @bhushanjawle– add your custom post type is already registered? You can see it the WordPress menu in admin?

    • #8018
      bhushanjawle
      Participant

      @Steve yes, it is registered and I can see it in WordPress Menu.
      To make it more concrete, sharing CPT registration with screenshot (attached)

      // Setup Payment Plan
          $post_types['payment-plan'] = array(
              'labels' => piklist('post_type_labels', 'Payment Plan')
              ,'title' => __('Enter a new Payment Plan Name')
              ,'public' => true
              ,'rewrite' => array('slug' => 'payment-plan')
          ,'show_in_rest' => true
          ,'supports' => array(
              'title'
              ,'revisions'
              )
          ,'hide_meta_box' => array(
              'revisions'
              ,'comments'
              ,'commentstatus'
              )
          ,'menu_icon' => 'dashicons-dashboard'
          ,'menu_position' => 10
          ,'capability_type' => array('payment-plan', 'payment-plans')
          ,'map_meta_cap' => true
          );
          return $post_types;
      

      This is code to add related post meta box

      piklist('field', array(
          'type' => 'group'
          ,'scope' => 'post'
          ,'label' => 'Related Posts'
          ,'relate' => array(
            'scope' => 'post'
          )
          ,'add_more'=> true
          ,'fields' => array(
            array(
              'type' => 'text'
              ,'field' => 'post_title'
              ,'label' => 'Amount Due'
              ,'columns' => 12
            )
            ,array(
              'type' => 'text'
              ,'field' => 'post_content'
              ,'label' => 'Post Content'
              ,'columns' => 12
              ,'attributes' => array(
                'rows' => 5
              )
            )
            ,array(
              'type' => 'hidden', 
              'field' => 'post_type', 
              'value' => 'payment-plan', 
              // 'scope' => 'post'
            )
            ,array(
              'type' => 'hidden'
              ,'field' => 'post_status'
              ,'value' => 'publish'
            )
          )
        ));
      

      Thanks.

      Attachments:
      You must be logged in to view attached files.
    • #8020
      bhushanjawle
      Participant

      For testing I have used title and content, I have also tried with custom fields for that post type. I am sure the content will not be saved as I have not added it in supports.
      To summarize:
      1. Is the post_type being passed correctly ?
      2. Can we populate other fields registered as custom metabox for related CPT data entry via relations.

      Thanks

Viewing 13 reply threads
  • You must be logged in to reply to this topic.