WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How does WordPress takes care of Custom Fields? (5 posts)

  1. bekar09
    Member
    Posted 5 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.

  2. MichaelH
    Member
    Posted 5 years ago #

    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()

  3. bekar09
    Member
    Posted 5 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.

  4. MichaelH
    Member
    Posted 5 years ago #

    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...

  5. bekar09
    Member
    Posted 5 years ago #

    many many thanks sir MichaelH. that worked like a charm.

Topic Closed

This topic has been closed to new replies.

About this Topic