• Resolved dkurth

    (@dkurth)


    I need to retrieve a singled value of a record set on the call back of ‘after’. The after call back is being set in the particular field I am assuming that usage of the ‘after’ is following the submission of field values, including

    add_filter('cmb2_override_XXXXX_meta_value', 'mmd_listings_mmdUserProfileDisplay', 10, 4);

    Is that assumption true?

    If it is true, how can I retrieve the values (verses the field arguments) from the record set?

    I could probably do this in Javascript again, but that adds a level of complication since I need the PostId in order to lookup the category of the postid..normally done in PHP.

    • This topic was modified 5 years, 8 months ago by dkurth.
    • This topic was modified 5 years, 8 months ago by dkurth.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    This parameter is going to be very much like the before param and likely the same situations. It’s going to receive the same field_args/field object passed parameters. Anything else pulled into your callback is going to be either via globals and/or your own function calls made there.

    Assuming that the field_args/field object are populated enough, I have to believe you could get all that you need to do get_post_meta() calls. Likely more with the field_args variable as that’d have the object ID for the post being rendered, and the field ID which gets used for the meta key.

    Despite the slightly vague naming, before and after don’t indicate the current state of saving a given post. Those just mean where your output would be shown in relation to the field being rendered on screen. If I click to add a new post, both will run and then the page finishes loading. Once I add in a title, maybe some content, a picture of a cat, and value for my CMB2 field, then it all gets saved, and the page refreshes, and then the before/after params run again, probably with a bit more info since the post has been processed and saved.

    Thread Starter dkurth

    (@dkurth)

    Thank you for everything. MUCH appreciated. When I did some dumps of the data, all that displayed was the field structure, so that solution did not work out. What did work out
    for the front end was reversing the order of data acquisition.

    1. I looked for all custom posts associated with the CMB2.
    2. I then get the categories assigned to the custom post and place this in an array
    3. I surround the java script code with PHP loop code and retrieve the row’s postid aka $ListId, from the CSS code directly, then compare it to the PHP array of postid used in the CMB2 system.

    I put the solution at:
    https://github.com/CMB2/CMB2/compare/develop…dskurth:patch-1#diff-49cb1c9a240af822c2e9a28587211ce2

    In case that is not visible, here is the php/javascript code combination.

    
     for($i=0; $i<$PostCnt; $i++)
       {
        $ListIdValue = $ListPosts[$i];
        $NewLabel    = $ListPostsLabel[$i];
       ?>
       <script type="text/javascript">
        jQuery( function( $ )    
          {
         /* Count the number of records in this set */
         var $box = $( document.getElementById( 'mmd_lists_UserProfile' ) );
         var $row = -1;	
         $box.find( '.cmb-group-title' ).each( function() 
           {
           var $this  = $( this );
           var $ListId = $this.next().find( '[id$="user_listid"]' ).val(); 
           $row=$row+1;
           if($ListId ==  <?php echo $ListIdValue; ?>)
             {
              var $box = $('label[for="mmdUserProfile_'+ $row +'_user_title"]');
              $box.text('<?php echo $NewLabel ?>');
             }
        });
     });
    	
    </script>
     <?php
       }   //  for($i=0; $i<$PostCnt; $i++)
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Retrieving Field value on ‘after’ call back’ is closed to new replies.