• Resolved psperkins

    (@psperkins)


    Setting the hidden field value to the name of the custom post type does not seem to be working for me.

    I have a post type named “lost_thing” and I am using a hidden field with CF7 Modules like so: [hidden post_type “lost_thing”] but every time I submit it it makes a “page” post type and not my custom one.

    Any ideas?

    https://www.ads-software.com/plugins/form-to-post/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi psperkins,

    I needed to do the same thing and could only find a solution where i changed the core files of the plugin (not advised, but I had no choice).

    In the ‘Form to Post’ plugin folder there is a file called ‘FormToPost_Plugin.php’ .. on line 142 there is some code as followed:

    $post = array(
                'post_status' => 'publish',
                'post_type' => 'post',
                'post_category' => array(0)
            );

    Change ”post_type’ => ‘post’,’ to whatever you need… worked for me!

    Thread Starter psperkins

    (@psperkins)

    Yeah that was what I ended up doing as well. Was hoping for something more…#AHEM…elegant I guess.

    Thanks for your input though!

    Plugin Author Michael Simpson

    (@msimpson)

    This is a mysterious bug. The code you cite is just setting default values for post status, type & category in case they are not set in the form. These are overwritten a little further down in the code:

    // Add in any additional fields
            foreach ($simpleFields as $field) {
                if (isset($cf7->posted_data[$field])) {
                    $post[$field] = stripslashes($cf7->posted_data[$field]);
                }
            }

    (where $simpleFields includes post_status, etc.)

    Since I cannot reproduce this behavior, I would be interested if someone having this issue would inject a call to write out the contents of $cf7->posted_data to a log file to see if you are in fact getting post_status.

    You could do this by adding this line:
    error_log('Form Submission: ' . print_r($cf7, true));

    and create a wp-content/plugins/contact-form-7-to-database-extension/php.ini file with an line that points to a where a log files should be written:
    error_log=/path/to/error_log.txt

    Hi,
    Here is a great tutorial on WordPress custom post type add form in frontend https://unitedwebsoft.in/blog/wordpress-custom-post-type-add-form-in-frontend-for-users/.
    also added to custom taxonomy with image upload field.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Post Type’ is closed to new replies.