Creating a custom field from a plugin hook in functions.php
-
I’m simply trying to use a plugin hook within my own function to add a custom field to each post when it’s published. But I can’t quite figure out how to make the function work. Here’s what I have so far:
function custom_medium($postID) { global $post; $postID = $post->ID; $custom = get_the_image( array( 'default_size' => 'large', 'link_to_post' => false, 'image_scan' => true ) ); update_post_meta($postID, 'medium', ''.$custom.''); } add_action('publish_post', 'custom_medium');
I’m using the Get The Image plugin to grab the first attached image for each post, and need to register what it finds as a custom field called “medium”.
As always, any help is greatly appreciated. Thanks in advance.
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Creating a custom field from a plugin hook in functions.php’ is closed to new replies.