Updating post meta after post publish
-
I am trying to resolve custom post field auto increment field problem.
Using ACF plugin.
I have tried approach to setup custom field named: sifra
I need this field to be auto increment.
I am trying to get max value of post meta filed “sifra” from database and then increment it by 1.
Using “publish_post” hook to update custom field with auto incremented value.So far this is my code but it doesn’t work:
function update_sifra($post_id) { if( ( $_POST['post_status'] == 'publish' ) && ( $_POST['original_post_status'] != 'publish' ) ) { $post = get_post($post_id); $maxsifra = $wpdb->get_results($wpdb->prepare( " SELECT MAX(sifra) FROM wp_postmeta " )); $nextsifra = $maxsifra++; update_post_meta($post, 'sifra', $nextsifra); } } add_action( 'publish_post', 'update_sifra' );
Please guide me to the right steps to make this work.
Thank you.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Updating post meta after post publish’ is closed to new replies.