Viewing 11 reply threads
  • Author
    Posts
    • #2135
      ianmuscat
      Member

      Hi,

      In relation to https://piklist.com/support/topic/displaying-content-from-advanced-add-mores/, thanks to your help I was able to get everything working properly, however, I need to be able to get an index of the add-more item. For instance, if the Piklist loop is outputting add-more item #2, I need to be able to print out ‘#2’.

      Also, ideally, I would also be able to get the number of add-more items for a given post/entry – so if a post has 4 items, I would be able to output ‘4 items’ outside of the ‘add-more’ template.

      I’m not sure what would be the most effective way to go about this, or if I can/should use the default Piklit loop at all for this.

      Any ideas on how this can be achieved?

      Ian

    • #2147
      ianmuscat
      Member

      Hi,

      I do apologize for several posts, however, I’m facing some challenges and I can’t seem to figure it out myself. I re-read my post and perhaps I might have not been as clear as to what I wish to achieve. My custom post type is outputting a series of add-more items, each one is being looped using the Piklist loop in a template file. So, far that works fine. However, I need to be able to also print out (in the template) what add-more item this is on.

      So, if I have the following array being outputted

      Array
      (
          [piklist_test_title] => Array
              (
                  [0] => Test
                  [1] => Test 2
              )
      
          [slide_content] => Array
              (
                  [0] => <p>some text.</p>
                  [1] => <p>some text.</p>
              )
      
          [piklist_test_content] => Array
              (
                  [0] => Array
                      (
                          [0] => 1687
                      )
      
                  [1] => Array
                      (
                          [0] => 
                      )
      
              )
      
          [piklist_test_color] => Array
              (
                  [0] => #6b6b6b
                  [1] => 
              )
      
          [piklist_test_option] => Array
              (
                  [0] => Array
                      (
                          [0] => option-1
                      )
      
                  [1] => Array
                      (
                          [0] => option-1
                      )
      
              )
      
      )

      I would need to be able to echo ‘#1’ if the array is at position [0] in the add-more template (the template that is being looped). An idea I had was to possibly use the following from @jasonhttps://gist.github.com/JasonTheAdams/d40351ecf5bca8a7e7f4#file-parse_piklist_array

      However, I haven’t been able to get that working properly either.

      Any input would be greatly appreciated, thanks in advance. Please let me know if any further information is required.

      Regards,
      Ian

    • #2159
      Steve
      Keymaster

      @ianmuscat– Just wanted to let you know we are looking into this.

    • #2161
      ianmuscat
      Member

      Hi Steve,

      Thank you so much – I’ll be awaiting your suggestion.

      Ian

    • #2163
      Jason
      Keymaster

      Hi Ian!

      Just because you mentioned the function I wrote, I wanted to let you know I just updated it (same gist). Use it like this:
      $array = parse_piklist_array(get_post_meta($post_id, 'field-name', true));

      If that doesn’t work (after grabbing the latest code), I’d be curious what issue you’re having.

    • #2169
      ianmuscat
      Member

      Hi Jason,

      Apologies for the late reply – I tried out your updated code and it works like a charm – this will be useful for counting the total number of ‘add-more’ items easily.

      However, I am still stuck with regards to knowing which item I am on inside of the Piklist loop. Once again, the idea is to be able to determine what index a particular ‘add-more’ item has so I can print it inside the add-more template which is getting repeated via the Piklist loop.

      Regards,
      Ian

    • #2170
      Jason
      Keymaster

      Being perfectly honest, I don’t use the piklist loop views as not to be limited by what Piklist exposes to the view loop. I prefer to parse the meta, and handle it myself from there. So I’d do something like this (as an example):

      $list = '';
      $faqs = parse_piklist_array(get_post_meta(get_the_ID(), 'faq', true));
      foreach($faqs as $index => $faq) {
        $list .= "<li>$index: <span>{$faq['question']}</span> {$faq['answer']}</li>";
      }
      
      $list = "<ul>$list</ul>";

      Of course it’d be great to use the Piklist loop as you’re intending, but if you need it now you can do something like that.

      Hope this helps!

    • #2171
      ianmuscat
      Member

      Hi Jason,

      Thank you so much for your input! I will try this out first thing tomorrow and let you know if I managed to get this to work.

      Thanks once again for your help.

      Regards,
      Ian

    • #2174
      ianmuscat
      Member

      Hi,


      @jason
      – Thank you so much for your help – I ended up using your solution to work around this.

      Many thanks,
      Ian

    • #3132
      azizultex
      Member

      Hi,

      Thanks for the Jason’s code. I get the function worked with to fetch value for below code:

      piklist('field', array(
          'type' => 'group'
          ,'field' => 'social_media'
          ,'label' => __('Social Media') 
          ,'columns' => 12
          ,'add_more' => true
          ,'fields' => array(
      	
                array(
                  'type' => 'text'
                  ,'field' => 'icon'
                  ,'columns' => 2
                  ,'attributes' => array(
                    'placeholder' => 'fa fa-facebook'
                  )
                )
                ,array(
                  'type' => 'text'
                  ,'field' => 'link'
                  ,'columns' => 7
                  ,'attributes' => array(
                    'placeholder' => 'https://www.facebook.com/worksfireinc'
                  )
                ),
      		    array(
                  'type' => 'text'
                  ,'field' => 'tooltip'
                  ,'columns' => 3
                  ,'attributes' => array(
                    'placeholder' => 'Facebook'
                  )
                )
          )
        ));

      I need to know if I can also fetch value for a bit advanced metaboxes like below.

      <?php
      piklist('field', array(
          'type' => 'group'
          ,'field' => 'workout_schedule'
          ,'label' => __('Tasks') 
          ,'columns' => 12
          ,'add_more' => true
          ,'fields' => array(
            array(
              'type' => 'select'
              ,'field' => 'day'
              ,'columns' => 12
              ,'choices' => array(
                'monday' => 'Monday'
                ,'tuesday' => 'Tuesday'
                ,'wednesday' => 'Wednesday'
                ,'thursday' => 'Thursday'
                ,'friday' => 'Friday'
                ,'saturday' => 'Saturday'
                ,'sunday' => 'Sunday'
              )
            )
            ,array(
              'type' => 'group'
              ,'field' => 'exercise_day'
              ,'add_more' => true
              ,'fields' => array(
                array(
                  'type' => 'text'
                  ,'field' => 'exercise'
                  ,'columns' => 8
                  ,'attributes' => array(
                    'placeholder' => 'Exercise'
                  )
                )
                ,array(
                  'type' => 'text'
                  ,'field' => 'exercise_reps'
                  ,'columns' => 2
                  ,'attributes' => array(
                    'placeholder' => 'Reps'
                  )
                )
                ,array(
                  'type' => 'text'
                  ,'field' => 'exercise_sets'
                  ,'columns' => 2
                  ,'attributes' => array(
                    'placeholder' => 'Sets'
                  )
                )
              )
            )
          )
        ));
      ?>

      Is it possible to fetch value for above metaboxes using Jason’s function?

      Thanks

    • #3138
      Jason
      Keymaster

      Hi @azizultex

      Use the PiklistHelper::parse_array function found here: https://github.com/JasonTheAdams/PiklistHelper

      That should work for both fields, as it works recursively to support nested groups. If there’s any problems please make an Issue on Github. 🙂

    • #3139
      azizultex
      Member

      Thanks @Jason, I will will look at this.

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