Viewing 3 reply threads
  • Author
    Posts
    • #2594
      slateb
      Member

      I have a field group called updates that I am trying to display in reverse order so that the last item I add displays as the most recent update. I’ve tried to use
      array_reverse but that doesn’t seem to work.

      $updates = get_post_meta($post->ID, 'all_program_updates', true);
      piklist(get_stylesheet_directory() . '/partials/program-updates', array('data' => $updates, 'loop' => 'data'));

      Is there a way to do this with the piklist function? To loop the data in reverse?
      Thanks for the help!!

    • #2595
      Jason
      Keymaster

      Hopefully Steve or someone who uses the Piklist template features will chime in, but I don’t personally use them.. the reason is the one that you’re experiencing now. I just want Piklist to store and retrieve the data for me, and I’ll determine how best to handle/manipulate it from there.

      If it’s a group, then I use my PiklistHelper::parse_array function to put it in an easier structure.

      I just use a foreach, parse through the content, and build the content. For example:

      $boxes = get_post_meta($post->ID, 'boxes_example', true);
      $boxes = array_reverse(PiklistHelper::parse_array($boxes));
      $list = '';
      foreach($boxes as $box)
        $list .= "<h2>{$box['caption']}</h2><p>{$box['content']}</p>";
      
      echo $list;

      Something like that, anyway. Now you can manipulate the array of data as you would any other array in php. No framework limitations. Hope this helps! 🙂

    • #2597
      slateb
      Member

      Yeah Jason I found your helper function after I posted that and just finished up the code. Works great!!
      Thanks so much.

    • #2598
      Jason
      Keymaster

      Glad to help! If you have any issues feel free to add an Issue on github or make a pull request to add anything! I’m hoping folks will start adding to that more once they use Piklist regularly and have an idea of what would be useful. 🙂

Viewing 3 reply threads
  • The topic ‘Reverse Display Order for Groups’ is closed to new replies.