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.

submitting 2 forms as 2 custom post types

  1. sdever
    Member

    Hi there,

    I have form 1, which I would like to show up as a draft post under custom post type "pv_listing" and form 2, which I would like to show up as a draft post under custom post type "pv_events"

    This thread http://forum.gravityhelp.com/topic/add-a-form-to-create-a-new-custom-post-type#post-3425 worked fine for me when I only had 1 form for 1 custom post type.

    So I tried to improvise, first by copying, amending, and pasting the whole snippet of code for form 2. When that didn't work, I tried modifying as below. I have zero coding skills, so both tries just made my screen go blank.

    add_filter( "gform_post_data", "update_post_type", 10, 2 );
    function update_post_type( $post_data, $form ) {
    	if( $form["id"] == '1' ) {
    		$post_data["post_type"] = "pv_listing";
    	elseif( $form["id"] == '2' ) {
    		$post_data["post_type"] = "pv_event";
    	}
    	return $post_data;

    Can you let me know the correct way to do this?

    Thanks!

    Posted 13 years ago on Tuesday August 10, 2010 | Permalink
  2. sdever
    Member

    Sorry, pv_events was a typo in my email -- the spelling in the code is correct

    Posted 13 years ago on Tuesday August 10, 2010 | Permalink
  3. sdever
    Member

    Okay, as I reread my post, I spotted the problem and used the code below, which works.

    But now I am encountering something very bizarre. I want to save this form on a child page of parent (top-level) page Events.

    When I do this, then click on "view page" , I get the 404 Not found message, even though I am clicking from inside the saved post. This happens regardless of what I name the page or the slug.

    When I remove the form, I can view it fine.
    When I save the page (with form) under any other parent page, I can view it fine.

    The problem only happens when I save it with the form, under the parent page Events.

    Do you have any idea why this is happening? I can find a workaround, but just curious if there's an answer...

    add_filter( "gform_post_data", "update_post_type", 10, 2 );
    function update_post_type( $post_data, $form ) {
    	if( $form["id"] == '1' ) {
    		$post_data["post_type"] = "pv_listing";
    	}
    	elseif( $form["id"] == '2' ) {
    		$post_data["post_type"] = "pv_event";
    	}
    	return $post_data;
    }
    Posted 13 years ago on Tuesday August 10, 2010 | Permalink
  4. 404 errors are usually associated with issues with your permalink. It is very strange that you only get the 404 when you have a form in your post.
    I don't know what could be causing your issue, but if you would like me to try to debug it, please email (alex[at]rocketgenius.com) me an FTP and WP admin login and I will try to find out what is causing this.

    Posted 13 years ago on Tuesday August 10, 2010 | Permalink