Home › Forums › Backend Issues (wp-admin) › Add acf field to post type AND to the quick edit screen › Reply To: Add acf field to post type AND to the quick edit screen
I know this is a bit late but I just had this same issue I was trying to solve. I managed to get a working proof of concept by Frankensteining a number of different tutorials together. I have an ACF field on the custom post type page called ‘homepage_order’ that I can enter data in and if I go to the posts list page I can see that content in a custom column and update the content from the Quick Edit box of each post. I am not a proficient PHP coder so I’m sure there are glaring errors and my security checks are not all there (some of them are causing the update to fail) but hopefully this will help point you in the right direction. If anyone has any comments on how I can make this better, I would be most appreciative.
//Adds the custom column to the exhibits posts list page
add_filter( 'manage_exhibits_posts_columns', 'heard_filter_posts_columns' );
function heard_filter_posts_columns( $columns ) {
$columns['homepage_order'] = __( 'Current Exhibits Order', 'heard' );
return $columns;
}
//Gets the data from the custom field populated in the exhibits post and adds it to the column
add_action( 'manage_exhibits_posts_custom_column', 'heard_homepageorder_column', 10, 2);
function heard_homepageorder_column( $column, $post_id ) {
// Image column
if ( 'homepage_order' === $column ) {
echo get_post_meta( $post_id, 'homepage_order', true );
}
}
//Creates a fillable field in the Quick Edit box
add_action( 'quick_edit_custom_box', 'heard_custom_edit_box_pt', 10, 3 );
function heard_custom_edit_box_pt( $column, $post_id ){
if($column == 'homepage_order'){
$html .= '<fieldset class="inline-edit-col-right ">';
$html .= '<div class="inline-edit-group wp-clearfix">';
$html .= '<label class="alignleft" for="homepage_order">Current Exhibits Order</label>';
$html .= '<input type="text" name="homepage_order" id="homepage_order" value="" />';
$html .= '</div>';
$html .= '</fieldset>';
}
echo $html;
}
//Saves any updates to the current exhibit order field in the Quick Edit box
add_action( 'save_post_exhibits', 'heard_update_custom_quickedit_box' );
function heard_update_custom_quickedit_box() {
//There are currently limited security measures in place on this. The quick edit field won't update when I add all of them. Still working on this.
//Check user permissions- this works
if ( 'page' == $_POST['homepage_order'] ) {
if ( !current_user_can( 'edit_page', $post_id ) )
return $post_id;
}
// save homepage_order updates in Exhibits- custom post type
if( isset( $_POST['homepage_order'] )) { // where homepage_order is defined in the <input name="homepage_order">
update_post_meta($_POST['post_ID'], 'homepage_order', $_POST['homepage_order']);
}
return; // finish the function call
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.