Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
novak.p90

Inline post update

Hi there everyone.
I have this issue,where I have columns of Advanced Custom Fields, and on the side in function.php I have sum of one of the fields with second one. My problem is, that when I update post conditional way, I all calculate as it should, but when edit those values inline, it doesnt do fucnctions(.php) as it doesnt update post as WP does normally.
I found your way to go around it, or at least I thought i did.
https://www.admincolumns.com/documentation/guides/update-modified-date-using-inline-edit-custom-fields/

But it did not work as expect,or at all for that matter. Is there any way to update post from inline editing?

My fucntion is this:

function my_acf_save_post( $post_id ) {  
// get new value
$CenaJedna = get_field('cena_1');
$CenaDve = get_field('cena_1');  
// do something
$CenaCelkem = $CenaJedna + $CenaDve;
update_field('cena_soucet', $CenaCelkem, $post_id);	
}
add_action('acf/save_post', 'my_acf_save_post', 20);

function my_acf_save_postt( $post_id ) {   
// get new value
$CenaJedna = get_field('cena_soucet');
$CenaDve = get_field('cena_registrace');
// do something
$CenaCelkem = $CenaJedna - $CenaDve;
update_field('rozdil_cen', $CenaCelkem, $post_id);
}
add_action('acf/save_post', 'my_acf_save_postt', 20);

function my_acf_save_postit( $post_id ) {   
// get new value
$CenaJedna = get_field('cena_soucet');
$CenaDve = get_field('cena_registrace');
// do something
$CenaCelkem = $CenaJedna / $CenaDve * 100;
update_field('rozdil_cen_procenta', $CenaCelkem, $post_id);
}
add_action('acf/save_post', 'my_acf_save_postit', 20);
5 years, 5 months ago
Stefan van den Dungen Gronovius
Developer

The documentation you found is indeed the page I would recommend and I do believe it can work with your code.
Our hook gives you a column and the post_id and based on your code, you only need the ID for your custom functions. Instead of calling the update_post method you can now call your custom function to run your custom code. The snippet should look something like this:

/**
 * @param AC\Column $column
 * @param int       $id
 */
function my_acp_after_ajax_column_save_update_post_date( $column, $id ) {
	if ( 'post' === $column->get_list_screen()->get_meta_type() ) {
		my_acf_save_post( $id );
		my_acf_save_postt( $id );
		my_acf_save_postit( $id );
	}
}

add_action( 'acp/editing/saved', 'my_acp_after_ajax_column_save_update_post_date', 10, 2 );

Just a tip, you might want to give your function names a more descriptive name :)

5 years, 5 months ago
novak.p90

Hi, we tried your function, but it doesn´t work. Can you try something else?

5 years, 5 months ago

You must be logged in to reply to this topic.