I would like to add custom fields automatically to all my custom post types weblogs
based on data from the author profile field.
My code:
function add_custom_field_automatically($post_ID) {
global $wpdb;
$curauth = get_userdata($author->ID);
if(!wp_is_post_revision($post_ID)) {
$themevalue = get_the_author_meta('themeperauthor', $author->ID);
$themename = 'themeperauthor';
add_post_meta($post_ID, $themename, $themevalue);
}
}
Please help.
create a simple query and loop over all posts with your function:
after you save this remove it (it only needs to run once).
the use your old function from above and hook it to save_post hook so every time a post is saved it will run