bekar09
Member
Posted 2 years ago #
Hi everybody,
I would like to know how wordpress assigns custom fields? Suppose I'm inserting a post through an external script by calling the function 'wp_insert_post', and i want to add a custom field for that particular post (say for example the thumbnail url) then how should i go about it? help is much appreciated.
You can update custom fields with update_post_meta().
Additional info:
If you're adding the thumbnail as an attachment to a post you may want to look at the wp_insert_attachment() function in wp-includes/post.php
Related:
wp_insert_post()
bekar09
Member
Posted 2 years ago #
Hi MichaelH,
thanks for the suggestion. can you elaborate how i can pass the thumbnail url as a custom field while calling the function 'wp_insert_post' function from an external file? shall i call the function 'add_post_meta'(<?php add_post_meta($post_id, $meta_key, $meta_value, $unique); ?>) after calling the 'wp_insert_post' function which returns the POST_ID and passing it to the 'add_post_meta'? Awaiting your reply.
shall i call the function 'add_post_meta'(<?php add_post_meta($post_id, $meta_key, $meta_value, $unique); ?>) after calling the 'wp_insert_post' function which returns the POST_ID and passing it to the 'add_post_meta'?
That sounds right...
bekar09
Member
Posted 2 years ago #
many many thanks sir MichaelH. that worked like a charm.