this is a snippet that might do what you want:
(add it in functions.php of your theme)
function addCustomFieldForumLink() {
/* to add a custom field with a link to a forum to all posts, /
/ update it on 'post edit' or 'post save' /
/ to show in post (within the loop) use <?php echo get_post_meta($post->ID,'forum_link',true); ?>
/ alchymyth 2010 */
global $wpdb;
$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ";
$pageposts = $wpdb->get_results($querystr, OBJECT);
// get a list of all published posts //
if ($pageposts):
foreach ($pageposts as $post):
setup_postdata($post);
// add the 'forum link' custom field to the post or update it //
$link_to_forum = 'https://#' // enter the full path to your forum //
add_post_meta($post->ID, 'forum_link', $link_to_forum, true);
update_post_meta($post->ID, 'forum_link', $link_to_forum);
// add the 'news link' custom field to the post or update it //
$link_to_news = 'https://#' // enter the full path to your news source //
add_post_meta($post->ID, 'news_link', $link_to_news, true);
update_post_meta($post->ID, 'news_link', $link_to_news);
endforeach;
endif;
}
add_action ( 'publish_post', 'addCustomFieldForumLink' );
add_action ( 'edit_post', 'addCustomFieldForumLink' );
the function will be called every time you publish a new post, or save edits on existing posts.
if a post does not have the custom field(s), the code will make and add the customfield and the custom value to the post;
if the custom field exists, the code will ‘update’ and keep just one value.
btw: make sure you dont have any empty line after the last ?>
in your functions.php; and observe the opening/closing of the php tags.
hope it works, good luck ??