Skip to content

Instantly share code, notes, and snippets.

@svenl77
Last active September 4, 2017 12:44
Show Gist options
  • Save svenl77/a5b9865bbec046b29900a49b7c9c8db3 to your computer and use it in GitHub Desktop.
Save svenl77/a5b9865bbec046b29900a49b7c9c8db3 to your computer and use it in GitHub Desktop.
BuddyForms: Add a new table column to the posts list table to display Form elements saved as post meta ( Custom Fields )
<?php
// Hook into the the-loop.php template and add an new table head
add_action('buddyforms_the_thead_tr_inner_last', 'my_buddyforms_the_thead_tr_inner_last', 10, 2);
function my_buddyforms_the_thead_tr_inner_last($post_id, $form_slug){
// Check if this is the correct form.
// Change "FORM_SLUG" to your form
if($form_slug != 'FORM_SLUG'){
return;
}
// Add a label to the table change 'Label' to your needs
?><th class="title"><span><?php _e( 'Label', 'buddyforms' ); ?></span></th><?php
}
// Add the td to the table row with the value of the post meta
add_action('buddyforms_the_table_tr_last', 'my_buddyforms_the_table_tr_last', 10, 2);
function my_buddyforms_the_table_tr_last($post_id, $form_slug){
// Check if this is the correct form.
// Change "FORM_SLUG" to your form
if($form_slug != 'posts'){
return;
}
// Get the post meta by the form element slug
// Change the "SLUG" to the form element slug.
$value = get_post_meta( $post_id, 'SLUG', true);
// Display the td with the value
echo '<td>' . $value . '</td>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment