Forums

posting post from front end (2 posts)

  1. bineet chaubey
    Member
    Posted 1 year ago #

    hi i am trying to create a theme in which user can post content from front end for doing show i am the code

    [Code moderated as per the Forum Rules. Please use the pastebin]

    i am find these code from
    http://wpshout.com/wordpress-submit-posts-from-frontend/
    this site my froblem is that i want to add a custom field value with post so i am using add_post_mata() function . but in this function how we can pass post->ID parameter to add custom field value in this post.

    please help me ?
    i am intermediate knowledge in php .
    i really appreciated your answer .

  2. cscscs
    Member
    Posted 1 year ago #

    Not sure that I understand, if your trying to retrieve the post ID try one of these. It works in most cases...

    // Works inside of the Loop
    function function_name() {
    global $post;
    $thePostID = $post->ID;
    }

    or:

    // Works in single post outside of the Loop
    function function_name() {
    global $wp_query;
    $thePostID = $wp_query->post->ID;
    }

    You would then use:
    <?php add_post_meta($thePostID, $meta_key, $meta_value, $unique); ?>

    Resource:
    http://www.mydigitallife.info/2006/06/24/retrieve-and-get-wordpress-post-id-outside-the-loop-as-php-variable/

Topic Closed

This topic has been closed to new replies.

About this Topic