On publish post update post meta value
-
I’d like to ask for a little help why code below doesnt work to upadate post meta value and display it as float. It did work at start but displayed 7 insted 7.4
function addAvg() { global $post; while (have_posts()) : the_post(); $xxx = get_post_meta($post->ID, 'x', true); $xxx1 = get_post_meta($post->ID, 'x1', true); $xxx2 = get_post_meta($post->ID, 'x2', true); $xxx3 = get_post_meta($post->ID, 'x3', true); $xxx4 = get_post_meta($post->ID, 'x4', true); $avgcho = ($xxx + $xxx1 + $xxx2 + $xxx3 + $xxx4)/5; update_post_meta($post->ID, 'avg', $avgcho); endwhile; } add_action('publish_post', 'addAvg');
Thanks for any help 🙂
- The topic ‘On publish post update post meta value’ is closed to new replies.