I created a function to save custom fields on publish a post. Something like this.

function create_fields() {  
    global $post;     
    $casa_id = $post->ID;  
    update_post_meta($post->ID, 'casa_id', $casa_id);  
}  
add_action('publish_post', 'create_fields');  

This function saves on a custom field some string.

Now the question:

How can i use this action on older posts? I have 1000 posts and i don’t want to refresh all the posts manually, is this possible?

3 Answers
3

you can do something like this:

$args = array(
    'posts_per_page' => 1000,
    'post_type' => 'post'
    );
$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) { 
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        $casa_id = $post->ID;
        update_post_meta($post->ID, 'casa_id', $casa_id);
    }
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *