add_action('init','likeincrease'); function likeincrease(){ $newValue = 50; $argslike = array( 'post_type' => 'portfolio', 'posts_per_page' => -1 ); $likequery = new WP_Query( $argslike ); while( $likequery->have_posts()) : $likequery->the_post(); $currentValue = get_post_meta($likequery->post->ID, '_likes'); if(!is_numeric($currentValue[0])) { $currentValue[0] = 0; } if ( $currentValue[0]<50 ) { $newValue = $currentValue[0]+$newValue; update_post_meta($likequery->post->ID, '_likes', $newValue); } endwhile; }