Hi @dgilfillan,
For this you’ll need to either update each meta field value directly in the database (which might be a lot of manual work if you have a lot of posts) or you could do this programmatically and save yourself some time: Assign/update the custom field value for all posts.
Thread Starter
fippy
(@dgilfillan)
Hi Hector,
thanks, I think I’ve managed it following the advice you gave… I created a snipped that ran ONLY ONCE with the following:
function update_my_metadata(){
$args = array(
'post_type' => 'post', // Only get the posts
'post_status' => 'publish', // Only the posts that are published
'posts_per_page' => -1 // Get every post
);
$posts = get_posts($args);
foreach ( $posts as $post ) {
// Run a loop and update every meta data
update_post_meta( $post->ID, 'views_total', '1' );
update_post_meta( $post->ID, 'views_daily', '1' );
update_post_meta( $post->ID, 'views_weekly', '1' );
update_post_meta( $post->ID, 'views_monthly', '1' );
}
}
// Hook into init action and run our function
add_action('init','update_my_metadata');
-
This reply was modified 5 years, 9 months ago by
fippy.
Awesome, thanks for the update. Make sure to remove that code from your site when you’re done though, otherwise your post meta will be reset every time someone views a page on your website (you can also just comment out the add_action(...) line if you wish to use the code again in the future.)