I've been searching for this and all I found was for new columns to create....so...
I have a column named Views which shows the number of views the post has. The column name in admin is tie_post_views and the post meta field is tie_views
I would like to edit and save the values in that field from the Quick Edit post option.
I appreciate your help.
Edit:
I found a new code that "works" but this is adding a new column and i only edited the meta but not quite what i need since i already have the column
/*
* New columns
*/
add_filter('manage_post_posts_columns', 'misha_price_and_featured_columns');
// the above hook will add columns only for default 'post' post type, for CPT:
// manage_{POST TYPE NAME}_posts_columns
function misha_price_and_featured_columns( $column_array ) {
$column_array['price'] = 'Price';
// the above code will add columns at the end of the array
// if you want columns to be added in another place, use array_slice()
return $column_array;
}
/*
* Populate our new columns with data
*/
add_action('manage_posts_custom_column', 'misha_populate_both_columns', 10, 2);
function misha_populate_both_columns( $column_name, $id ) {
// if you have to populate more that one columns, use switch()
switch( $column_name ) :
case 'price': {
echo '$'.get_post_meta( $id, 'tie_views', true );
break;
}
endswitch;
}
/*
* quick_edit_custom_box allows to add HTML in Quick Edit
* Please note: it files for EACH column, so it is similar to manage_posts_custom_column
*/
add_action('quick_edit_custom_box', 'misha_quick_edit_fields', 10, 2);
function misha_quick_edit_fields( $column_name, $post_type ) {
// you can check post type as well but is seems not required because your columns are added for specific CPT anyway
switch( $column_name ) :
case 'price': {
// you can also print Nonce here, do not do it ouside the switch() because it will be printed many times
wp_nonce_field( 'misha_q_edit_nonce', 'misha_nonce' );
// please note: the classes could be:
// inline-edit-col-left, inline-edit-col-center, inline-edit-col-right
// each class for each column, all columns are float:left,
// so, if you want a left column, use clear:both element before
// the best way to use classes here is to look in browser "inspect element" at the other fields
// for the FIRST column only, it opens element, all our fields will be there
echo '
';
echo '
Price
';
break;
}
endswitch;
}
/*
* Quick Edit Save
*/
add_action( 'save_post', 'misha_quick_edit_save' );
function misha_quick_edit_save( $post_id ){
// check user capabilities
if ( !current_user_can( 'edit_post', $post_id ) ) {
return;
}
// check nonce
if ( !wp_verify_nonce( $_POST['misha_nonce'], 'misha_q_edit_nonce' ) ) {
return;
}
// update the price
if ( isset( $_POST['price'] ) ) {
update_post_meta( $post_id, 'tie_views', $_POST['price'] );
}
}