Tagged: add_more, parser function
- This topic has 11 replies, 4 voices, and was last updated 7 years, 1 month ago by
azizultex.
-
AuthorPosts
-
-
August 4, 2014 at 2:53 pm #2135
ianmuscatMemberHi,
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
-
August 5, 2014 at 7:24 am #2147
ianmuscatMemberHi,
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 @jason – https://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 -
August 5, 2014 at 3:53 pm #2159
SteveKeymaster@ianmuscat– Just wanted to let you know we are looking into this.
-
August 5, 2014 at 4:00 pm #2161
ianmuscatMemberHi Steve,
Thank you so much – I’ll be awaiting your suggestion.
Ian
-
August 5, 2014 at 4:11 pm #2163
JasonKeymasterHi 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.
-
August 6, 2014 at 8:27 am #2169
ianmuscatMemberHi 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 -
August 6, 2014 at 12:09 pm #2170
JasonKeymasterBeing 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!
-
August 6, 2014 at 3:33 pm #2171
ianmuscatMemberHi 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 -
August 7, 2014 at 6:30 am #2174
-
December 25, 2014 at 4:42 pm #3132
azizultexMemberHi,
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
-
December 29, 2014 at 12:18 pm #3138
JasonKeymasterHi @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. 🙂
-
December 29, 2014 at 12:35 pm #3139
-
-
AuthorPosts
- You must be logged in to reply to this topic.