Add custom field to all posts in specific category

You can use WordPress functions to do this and just run it once, a fast example would be.

function wpse_85236_add_photo_field(){

global $post;
$photoquery = new WP_Query('posts_per_page=-1');

while ( $photoquery->have_posts() ) : $photoquery->the_post();

    if ( in_category( 'photography' )) {
    add_post_meta($post->ID, 'category', 'photography', true);
    }

endwhile;
}
add_action( 'init', 'wpse_85236_add_photo_field' );

Remember to remove the function after it runs because you don’t want it to run on every load.

Leave a Comment