Tagged: custom fields, groups
- This topic has 13 replies, 3 voices, and was last updated 6 years, 11 months ago by
Steve.
-
AuthorPosts
-
-
June 18, 2013 at 5:12 pm #853
Carla ChalmersMemberI am currently setting up a Pedigree CPT. The pedigree fields on the post edit screen need to have a specific table type layout and I need to remove the piklist-label-container. Any help on how I can achieve this would be appreciated:
-
June 18, 2013 at 9:33 pm #854
jchambMember@txhorselady. If i’m taking the correctly you should be able to hook up a custom template with out a label, and then add it to your field. Here is an example.
In your functions.php add
add_filter('piklist_field_templates', 'add_piklist_field_templates'); function add_piklist_field_templates($templates) { $templates['no_label'] = '[field_wrapper] <div id="%1$s" class="%2$s"> [field_description_wrapper] <small>[field_description]</small> [/field_description_wrapper] [field] </div> [/field_wrapper]'; return $templates; }and then in your meta-box file
piklist('field', array( 'type' => 'group' ,'field' => 'my_group' ,'add_more' => true ,'label' => '' ,'description' => '' ,'template' => 'no_label' // custom template to not add label wrap ,'fields' => array( array( 'type' => 'textarea' ,'field' => 'column_1' ,'label' => 'Column 1' ,'columns' => 6 ) ,array( 'type' => 'textarea' ,'field' => 'column_2' ,'label' => 'Column 2' ,'columns' => 6 ) ) ));-
March 6, 2015 at 3:31 pm #3388
SteveKeymasterThe format for Field Templates has changed. Please refer to the official docs >
-
-
June 19, 2013 at 8:38 am #855
Carla ChalmersMembercool … I will give that a try. I was trying to insert an image of what I want but I can’t seem to get it to load on the screen. Here is another try

-
June 22, 2013 at 10:24 pm #859
Carla ChalmersMemberIs there a way that I can use a table to lay this out in the admin area?
-
June 22, 2013 at 11:17 pm #860
Carla ChalmersMemberNever mind …. I figured it out Woo Hoo!!! I love Piklist
-
June 24, 2013 at 6:40 am #861
Carla ChalmersMemberOK, so I’m having a bit of trouble returning the field values on the front end. Here is the result of my code for the backend:

I used a bit of css to hide the unnecessary fields for this bit of code (to save space here I only pasted the code for the first row):
piklist(‘field’, array(
‘type’ => ‘group’
,’field’ => ‘mhs_pedigree’
,’position’ => ‘start’
,’template’ => ‘no_label’ // custom template to not add label wrap
,’fields’ => array(
//row 1
array(
‘type’ => ‘text’
,’field’ => ‘spacer1′
,’label’ => __(‘.’)
,’columns’ => 4
,’position’ => ‘start’
,’attributes’ => array(
‘class’ => ‘mhs_spacer’
)
)
,array(
‘type’ => ‘text’
,’field’ => ‘spacer2′
,’label’ => __(‘.’)
,’columns’ => 4
,’attributes’ => array(
‘class’ => ‘mhs_spacer’
)
)
,array(
‘type’ => ‘text’
,’field’ => ‘mhs_c3-1′
,’label’ => __(‘C3-1′)
,’value’ => ‘C3-1′
,’columns’ => 4
,’position’ => ‘end’
)
)
));and so on …..
I am unable to put the individual values in my post template using this code:
<?php echo get_post_meta($post->ID, ‘mhs_pedigree[mhs_c1-1]’, true);?>
What am I doing wrong? Each mhs_c?-? field will be placed in respective table cells on the front end.
-
June 24, 2013 at 9:32 am #862
SteveKeymaster@txhorselady– The first thing you should do is see how WordPress is saving the values. Something like this will help you visualize the data:`$meta = get_post_custom($post_id);
print_r($meta);`Once you see the output, you can grab it properly.
This is standard WordPress, using a standard WordPress function… Piklist doesn’t do anything accept help you create the field easily. That’s one of the things that makes Piklist awesome.
-
June 24, 2013 at 9:53 am #865
Carla ChalmersMemberPardon my ignorance but I’m still learning PHP. Here is the result for that row and I’m not sure how to extract only the mhs_c3-1 value
[mhs_pedigree] => Array ( [0] => a:3:{s:7:”spacer1″;s:0:””;s:7:”spacer2″;s:0:””;s:8:”mhs_c3-1″;s:10:”grand sire”;} )
Would there be a better way of laying out the admin screen to achieve the result that I need?
-
June 24, 2013 at 11:20 am #866
jchambMemberlooks like the data is serialized. not sure what your current call looks like but once you have that array as a variable with that exact array structure you can do this
$mhs_pedigree = unserialize($mhs_pedigree[0]);$mhs_pedigree should then be an array of individual values as an array.
-
June 24, 2013 at 11:55 am #867
Carla ChalmersMemberNow I am lost as to what to do with that bit of code
-
June 24, 2013 at 9:19 pm #868
jchambMemberSorry I was assuming you knew that the array was showing from what steve posted. Example step by step, starting from what Steve posted.
$meta = get_post_custom($post_id);
Then when you do the print_r you should see an array that looks something like you postedArray ( [mhs_pedigree] => Array ( [0] => a:3:{s:7:”spacer1″;s:0:”";s:7:”spacer2″;s:0:”";s:8:”mhs_c3-1″;s:10:”grand sire”;} ) )So $meta is now equal to an associative array that contains the key ‘mhs_pedigree’. mhs_pedigree is equal to another array which the first value (0) is serialized data.
Basically what happens is when the data is saved by wordpress it takes your group piklist field, and creates and meta value, now for each field inside of that group it takes all of them as an array and runs php’s serialize function on them to create a single string of data. essinitally making your group field equal to a string.
Okay, back to how you can use this. You need to be able to access each field’s value back individually from your mhs_pedigree, so lets follow the array down to the serialized data and convert that back to an array of data you can use.
// Grab all of our custom post types $meta = get_post_custom($post_id); // turn mhs_pedigree into its own array. $mhs_pedigree = unserialize($meta['mhs_pedigree'][0]); print_r($mhs_pedigree);now the printed screen values should show something along this line (based on your fields)
Array ( [spacer1] => 'some_value', [spacer2] => 'some_value', [mhs_c3-1] => 'some_value )so to use those in your template then now you can user
<?php echo $mhs_pedigree['mhs_cs-1']; ?>just note that i didn’t test anything, just trying to provide a rough example to explain what your seeing.
-
June 24, 2013 at 9:40 pm #870
Carla ChalmersMemberWoo Hoo …. You are so awesome!!! Thank you very much.
-
June 24, 2013 at 10:42 pm #871
-
-
AuthorPosts
- The topic ‘Grouped Fields Layout’ is closed to new replies.