Viewing 2 reply threads
  • Author
    Posts
    • #7333
      intrepidrealist
      Participant

      Hi!
      I’ve got all fields showing their data on a custom post type single page except a group of fields for birthday.

      This is my code in the child-fields.php:

      piklist('field', array(
      	  'type' => 'group'
      	  ,'field' => 'birthday_group'
      	  ,'label' => 'Birthday'
      	  ,'list' => false
      	  ,'attributes' => array(
          'class' => 'text'
          ,'wrapper_class' => 'birth_day'
          )
      	  ,'fields' => array(
      		array(
          'type' => 'select'
          ,'field' => 'birth_month'
          ,'label' => 'Month'
          ,'choices' => array(
      	   '' => 'Month'
          ,'jan' => 'January'
          ,'feb' => 'February'
          ,'mar' => 'March'
          ,'apr' => 'April'
          ,'may' => 'May'
          ,'jun' => 'June'
          ,'jul' => 'July'
          ,'aug' => 'August'
          ,'sep' => 'September'
          ,'oct' => 'October'
          ,'nov' => 'November'
          ,'dec' => 'December'
          ))
      		,array(
          'type' => 'select'
          ,'field' => 'birth_day'
          ,'label' => 'Day'
          ,'choices' => array(
      	   '' => 'Day'
          ,'1st' => '1'
          ,'2nd' => '2'
          ,'3rd' => '3'
          ,'4th' => '4'
          ,'5th' => '5'
          ,'6th' => '6'
          ,'7th' => '7'
          ,'8th' => '8'
          ,'9th' => '9'
          ,'10th' => '10'
          ,'11th' => '11'
          ,'12th' => '12'
          ,'13th' => '13'
          ,'14th' => '14'
          ,'15th' => '15'
          ,'16th' => '16'
          ,'17th' => '17'
          ,'18th' => '18'
          ,'19th' => '19'
          ,'20th' => '20'
          ,'21st' => '21'
          ,'22nd' => '22'
          ,'23rd' => '23'
          ,'24th' => '24'
          ,'25th' => '25'
          ,'26th' => '26'
          ,'27th' => '27'
          ,'28th' => '28'
          ,'29th' => '29'
          ,'30th' => '30'
          ,'31st' => '31'
          ))
          ,array(
          'type' => 'select'
          ,'field' => 'birth_year'
          ,'label' => 'Year'
          ,'choices' => array(
      	   '' => 'Year'
          ,'1997' => '1997'
          ,'1998' => '1998'
          ,'1999' => '1999'
          ,'2000' => '2000'
          ,'2001' => '2001'
          ,'2002' => '2002'
          ,'2003' => '2003'
          ,'2004' => '2004'
          ,'2005' => '2005'
          ,'2006' => '2006'
          ,'2007' => '2007'
          ,'2008' => '2008'
          ,'2009' => '2009'
          ,'2010' => '2010'
          ,'2011' => '2011'
          ,'2012' => '2012'
          ,'2013' => '2013'
          ,'2014' => '2014'
          ,'2015' => '2015'
          ,'2016' => '2016'
          ,'2017' => '2017'
          ,'2018' => '2018'
          ,'2019' => '2019'
          ,'2020' => '2020'
          )))
        ));

      And this is what I have in the template:

      <li>Birthday: <strong><?php echo get_post_meta($post->ID, 'birth_month', true); ?> <?php echo get_post_meta($post->ID, 'birth_day', true); ?>, <?php echo get_post_meta($post->ID, 'birth_year', true); ?></strong></li>

    • #7335
      jrcreative
      Member

      @intrepidrealist Grouped fields are stored as serialized data within the main group field.

      There are two ways you can get at the data you want.

      1. Remove the line ,'field' => 'birthday_group' and it will store the fields in the group as individual post_meta fields. That would be a simple solution and your code for display above should work.

      2. Access the data within ‘birthday_group’ and unserialize it. From there you’ll be able to access the individual elements.

      $birthday = get_post_meta($post->ID, 'birthday_group',true);
      $birthday = maybe_unserialize($birthday); // a nice WordPress function that checks if the content is actually serialized data
      echo $birthday['birth_month'].' ';
      echo $birthday['birth_day'].', ';
      echo $birthday['birth_year'];
    • #7341
      intrepidrealist
      Participant

      jrcreative!!

      That did the trick and solution filed for future use!
      Thank you!

Viewing 2 reply threads
  • The topic ‘data from grouped fields not showing up on frontend’ is closed to new replies.