Support

Search results for ""

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

acp/editing/saved – how to get it work

Hi Stefan, I am sorry to bother with this again.

I am trying to get the funcions work after inline editing,but with no luck at all.
I went to Documentation on acp/editing/saved, that should run after value is stored in column.

I took the last example, because you mention there it will run custom method. All I need is sum of two columns to calculate, one of which i already have and second one is user inputed in Inline Edit.

So my current code looks like this:

function my_acp_after_ajax_column_save_update_custom_field_value( $column, $id, $value ) {

	// Check for a custom field column
	if ( ! $column instanceof AC_Column_Meta ) {
		return;
	}

	$custom_field = 'my_custom_field';
	$post_type = 'post';

	if ( $post_type === $column->get_post_type() && $custom_field === $column->get_meta_key() ) {

		// Trigger a custom method.
		$CenaJedna = get_field('cena_soucet');
		$CenaDve = get_field('cena_registrace');
		$CenaCelkem = $CenaJedna - $CenaDve;
		update_field('rozdil_cen', $CenaCelkem, $post_id);
	}
}
add_action( 'acp/editing/saved', 'my_acp_after_ajax_column_save_update_custom_field_value', 10, 2 );

I am not php savvy, I can barely translate what those few lines should do, but as for the sum funcion, this one works when post is updated classic way. Should be ok then,by definition.

Now with this code, when I change said column (cena_registrace), all I get is unending buffering. (https://i.imgur.com/VvMXWgc.png)

What am I doing wrong? Thank you in advance for your help.

5 years, 2 months ago
Stefan van den Dungen Gronovius
Developer

Although I’m not familiar with your setup, I wrote a new snippet based on what I think should happen. I placed some comments in the code for you to have a look at. I hope this will help you further with using this specific hook.

/**
 * @param AC\Column $column
 * @param int       $id
 */
function my_acp_after_ajax_column_save_update_custom_field_value( $column, $id ) {
	// Check for a custom field column
	if ( ! $column instanceof AC\Column\Meta ) { // Example checked wrong instance, this is the new one
		return;
	}

	$custom_field = 'my_custom_field'; // Are you sure this is the custom field that is updated? Based on the custom fields you use below, I suspect you want to use on or both of those values (cena_soucet)

	if ( 'post' === $column->get_post_type() && $custom_field === $column->get_meta_key() ) {

		// Trigger a custom method.
		$CenaJedna = get_field( 'cena_soucet', $id ); // Specifiy the ID since you're working with Ajax and the post ID might not been set
		$CenaDve = get_field( 'cena_registrace', $id ); // Same as above
		$CenaCelkem = $CenaJedna - $CenaDve;
		update_field( 'rozdil_cen', $CenaCelkem, $id ); // Change $post_id to the actual use variable $id
	}

}

add_action( 'acp/editing/saved', 'my_acp_after_ajax_column_save_update_custom_field_value', 10, 2 );
5 years, 2 months ago
novak.p90

Now i get it!
Stefan you are awesome,thank you very much.

Key change is the comment on the $custom_field = ‘my_custom_field’; row, becuase I did not know that I need to have field that is being updated there. After few shuffles it works as a charm.

(Field cena_soucet is set, field cena_registrace is the one being changed by user)

Again, THANK YOU.

5 years, 2 months ago
Stefan van den Dungen Gronovius
Developer

You’re welcome, I’m glad you got it working.
I will close this topic

5 years, 2 months ago

You must be logged in to reply to this topic.