- This topic has 7 replies, 2 voices, and was last updated 6 years, 7 months ago by
Steve.
-
AuthorPosts
-
-
June 24, 2015 at 12:33 pm #3917
DanielMemberI’m new to picklist, I have read through most of the documentation. Perhaps this has already been brought up but I couldn’t find any information.
Often, the designers I work with build pages broken down into several small template pieces, so that we can reuse those small templates everywhere. This gives the client more flexibility when building pages and also less coding on my side.
I am coming from the ACF world, so bear with me… I’m trying to figure out a way where I can repeat a metabox on the same page. I am not talking about repeating the same field (with the add more option), but repeating the entire group.
Say I have a metabox with 3 fields (section-title, section-image,section-description) and I want to use this metabox at the top of the page, but then again at the bottom.
1. What would be the best approach to accomplish this with Picklist?
2. Would I have to re-create all fields in another group again?
3. I am wondering if people have also been creating these metaboxes templates programmatically by running functions to construct the field arrays? On a big project, I can’t imagine someone copying and pasting the same field several times on different metaboxes (editing that would be a huge headache). -
June 24, 2015 at 4:30 pm #3918
SteveKeymaster@danielatpush10com– Welcome to the Piklist community!
The easiest way to do this to just duplicate the file, and change the field names… since you can’t have two fields on the same form with the same name.
You can also, create a function to hold your field data. This function would NOT go in the parts/ folder. Probably in your plugin file or functions.php.
Then just call the function from your parts/ folder.
Does that makes sense?
-
June 25, 2015 at 9:35 am #3919
DanielMemberYep. That’s what I thought. Thanks.
-
June 25, 2015 at 9:48 am #3920
SteveKeymaster@danielatpush10com— Do you find doing it this way is easier than ACF?
-
June 26, 2015 at 11:10 am #3921
DanielMemberI don’t like the idea of having to copy and paste fields if I can just reuse them with a function. So the function approach I think will work just fine. I will need to find a way to always create a unique field slug each time, but that shouldn’t be too much of an issue.
I can see this taking a lot longer to setup at first, compared to ACF. However I can also see a bit more flexibility. -
June 26, 2015 at 12:10 pm #3922
SteveKeymasterHere’s something that should get you started. It can definitely be improved. Like passing multiple args, but this is the quick version.
Place this function in your main plugin file, or your themes functions.php file. This is where you can define all your field types.
function my_get_field($field, $prefix = null) { switch ($field) { case 'my_first_field': $field = array( 'type' => 'radio' ,'field' => $prefix . $field ,'label' => __('First Field') ,'choices' => array( 'one' => 'One' ,'two' => 'Two' ,'three' => 'Three' ) ); break; case 'my_second_field': $field = array( 'type' => 'text' ,'field' => $prefix . $field ,'label' => __('Second Field') ); break; default: return; break; } return $field; }Then call it from your parts folder:
piklist('field', my_get_field('my_first_field', 'my_prefix_'));Let me know if that works for you.
-
June 30, 2015 at 4:51 pm #3938
DanielMemberThanks Steve.
-
July 1, 2015 at 9:09 am #3942
SteveKeymasterGreat! Closing ticket.
-
-
AuthorPosts
- The topic ‘Repeating metaboxes within the same page’ is closed to new replies.