PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

update_post_meta with Custom post_type

  1. I have a custom post_type called, "lessons" which has meta fields that I populate with a gravity form.

    I then have a "duplicate" of the form that loads on a separate page and dynamically populates the content with the meta information and is supposed to let people update the post.

    I have a gform_after_submission hook to update the meta data, but because it's a custom post_type it's not working.

    Here's what I have for the function to update the meta...

    function gf_edit_plans( $entry, $form ) {
        global $post;
    		$monday_lesson = $_POST['20'];
    		update_post_meta($postID, 'monday_lesson', $monday_lesson );
    }
    add_action( 'gform_after_submission_10', 'gf_edit_plans', 10, 2 );

    Any ideas?
    I've been racking my brain on this one for hours!!

    Thanks.

    Posted 7 years ago on Wednesday July 4, 2012 | Permalink
  2. I think the problem is that $postID will not contain the ID of the post. Should that be $post->ID? Otherwise, where does $postID get defined? Can you echo the value of $postID and see what it contains?

    Also, outside the loop, you sometimes need to use this:

    global $wp_query;
    $thePostID = $wp_query->post->ID;
    Posted 7 years ago on Wednesday July 4, 2012 | Permalink
  3. It is grabbing it... but it may not be grabbing it correctly.

    Meaning I can echo it onto the page, but when I added in what you gave it "updated" the post, but it simply deleted all the entries.

    Have a look...

    Here's the template page...
    http://pastebin.com/kUHyp19H

    And here's the functions page...
    http://pastebin.com/3L6TZk2m

    Posted 7 years ago on Wednesday July 4, 2012 | Permalink
  4. Any other thoughts on this?
    I've still had no luck.

    Posted 7 years ago on Thursday July 5, 2012 | Permalink
  5. "but it simply deleted all the entries"

    That seems sort of scary.

    For troubleshooting, I would start by determining if you can retrieve the post. Can you var_dump the $postID and log it, display it, or email it to yourself?

    Once you know you have the correct post, it's a matter of updating the post_meta, correct?

    Posted 7 years ago on Friday July 6, 2012 | Permalink
  6. Got it!!

    All I had to do was change the "$_POST" to "$entry".
    I don't know why I hadn't noticed that.

    Thanks for the help!

    Posted 7 years ago on Friday July 6, 2012 | Permalink
  7. Glad you figured that out. Thanks for the update.

    Posted 7 years ago on Friday July 6, 2012 | Permalink

This topic has been resolved and has been closed to new replies.