• GF 1.8.22

    I setup 5 CPTs and 5 forms to load each one.

    Trying to rationalise to a single form that selects the CPT and then stores relevant (similar) details using Conditionals.

    As the CPT selection is a backend feature using GF+CPT on Title, I cannot find a way to select (eg Dropdown) on the front-end GF form and store the selected CPT – every attempt has resulted in a Post.

    Have searched for hours, happy to attempt php coding, but getting nowhere. Any suggestions (other than stick with 5 forms)?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hai.
    Had the same issue.
    And found this link to do it myself:
    https://bay-a.co.uk/wordpress-tips/gravity-forms-custom-post-from-form/

    Happy coding 😉

    Thread Starter rdellconsulting

    (@rdellconsulting)

    Thanks for this. I had seen it before but skipped over it. I’ll have to try again.

    Looks like it skips GF+CPT plugin which is probably what I need to do.

    When using this solution, you indeed do not need this plugin…

    I have implemented it myself now with the function shown below.
    It can be used by any form, you don’t need to use the form id.
    It checks whether there is a post_id defined in the entry.
    Next, it checks all fields supplied whether the value contains an existing post_type.
    In the form itself, I used a dropdown field to enable the user to select the post_type. Make sure that the values of the dropdown correspond with the post_types defined.

    /**
     * Use a custom post type if defined by a field in the form
     *
     */
    public function wps_gf_set_post_type($entry, $form) {
    
    	// Get the post_id if it exists
    	if (isset($entry['post_id'])) {
    		$post_id = $entry['post_id'];
    	} else {
    		return;
    	}
    
    	// Check the values of the form fields
    	if (isset($form['fields'])) {
    		foreach ($form['fields'] as $field) {
    			if (isset($entry[$field['id']])) {
    				// Get the value entered for this field
    				$entry_value = $entry[$field['id']];
    				// If an existing post_type is found, then use it for this post
    				if (post_type_exists($entry_value)) {
    					set_post_type($post_id, $entry_value);
    					return;
    				}
    			}
    		}
    	}
    }
    Thread Starter rdellconsulting

    (@rdellconsulting)

    Thank you so much. Will try it out in the next few days.

    This is my frustration with GF that they don’t provide useful snippets like this. I guess they rely on the community to provide the answers.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Select CPT on front-end?’ is closed to new replies.