0

I created a form called 'Books' which has the fields:

  • Title (Post Title)
  • Author
  • Genre (Dropdown - fantasy, horror, drama... etc)
  • ISBN Number
  • Status (Dropdown - Default Option - Published, additional option - Promoted)

This form creates and populates a custom post type called books, which has the custom meta fields:

  • Author
  • Genre
  • ISBN Number
  • Status
  • Promoter

I have a second form called 'Promoter' which show up in my single-books.php template file in my wordpress theme. The form shows up on the bottom of the page if the status is "Published" with the single text field for a person to enter their name for support and change the status from published to promoted. I spent a lot of time on the gravity forums site looking for an answer, and I came up with:

add_action("gform_post_submission_5", "books_promoter", 10, 4);
function books_promoter($entry, $form) {
        global $post;
        global $wp_query;

        $post_id = get_the_ID(); // $entry['post_id'];

        $post_data['status'] = get_post_meta($postID,'status', true);
        $post_data['promoter'] = get_post_meta($postID,'promoter', true);

        $status = $entry['5'];
        $promoter = $entry['6'];

        update_post_meta($post_id, 'books_status', $status );
        update_post_meta($post_id, 'books_promoter', $promoter );
}

This function gets the post ID and blank post meta field and then updates the post meta. For some reason though it does not work. I think it might be with the $post_id inside the template file loop, but I was wondering if anyone had any opinions on a better way to do this.

closed as off-topic by Pieter Goosen, Nicolai, birgire, Johannes Pille, mrwweb Sep 1 '14 at 14:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – Pieter Goosen, Nicolai, birgire, Johannes Pille, mrwweb
If this question can be reworded to fit the rules in the help center, please edit the question.

  • You are calling it $post_id and then later $postID - perhaps this is the cause for the problem? – GhostToast Nov 7 '13 at 21:45
  • @GhostToast you're my hero, I can't believe I just did that, amateur hour. Thanks again, worked perfectly. Also had to change gform_post_submission to gform_after_submission since post is depricated. – Rizzo Nov 8 '13 at 14:43
1

Here's the repair, for good measure and anyone curious:

add_action("gform_after_submission_5", "books_promoter", 10, 4);
function books_promoter($entry, $form) {
        global $post;
        global $wp_query;

        $post_id = get_the_ID(); // $entry['post_id'];

        $post_data['status'] = get_post_meta($post_id,'status', true);
        $post_data['promoter'] = get_post_meta($post_id,'promoter', true);

        $status = $entry['5'];
        $promoter = $entry['6'];

        update_post_meta($post_id, 'books_status', $status );
        update_post_meta($post_id, 'books_promoter', $promoter );
}
  • You may want to look at gform_update_meta() instead of update_post_meta(). As far as I'm aware gravity forms stores entries in a separate table. So while update_post_meta() may work for lower form ID numbers it will start to fail once your form entries exceed the number of blog posts on your site (if that makes sense) – dtbaker May 28 '17 at 2:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.