• Resolved collinsavenue

    (@collinsavenue)


    Here’s the thing. My blog uses automatic posts that gets then signed to specific users. The problem is that each post is created without selecting WPUF form from the dropdown. I only have one form.

    Can you tell me a code snippet or what file to change so that my form would be selected by default in WPUF dropdown on posts?

    Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter collinsavenue

    (@collinsavenue)

    Somehow I need to change the option value from <option value=””>–</option> to my id form by default but no idea how.

    /**
         * Form selection meta box in post types
         *
         * Registered via $this->add_meta_box_form_select()
         *
         * @global object $post
         */
        function form_selection_metabox() {
            global $post;
    
            $forms = get_posts( array('post_type' => 'wpuf_forms', 'numberposts' => '-1') );
            $selected = get_post_meta( $post->ID, '_wpuf_form_id', true );
            ?>
    
            <input type="hidden" name="wpuf_form_select_nonce" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
    
            <select name="wpuf_form_select">
                <option value="">--</option>
                <?php foreach ($forms as $form) { ?>
                <option value="<?php echo $form->ID; ?>"<?php selected($selected, $form->ID); ?>><?php echo $form->post_title; ?></option>
                <?php } ?>
            </select>
            <?php
        }
    
        /**
         * Saves the form ID from form selection meta box
         *
         * @param int $post_id
         * @param object $post
         * @return int|void
         */
        function form_selection_metabox_save( $post_id, $post ) {
            if ( !isset($_POST['wpuf_form_select'])) {
                return $post->ID;
            }
    
            if ( !wp_verify_nonce( $_POST['wpuf_form_select_nonce'], plugin_basename( __FILE__ ) ) ) {
                return $post->ID;
            }
    
            // Is the user allowed to edit the post or page?
            if ( !current_user_can( 'edit_post', $post->ID ) ) {
                return $post->ID;
            }
    
            update_post_meta( $post->ID, '_wpuf_form_id', $_POST['wpuf_form_select'] );
        }

    Is it anyway possible to set default form per post type?

    Thread Starter collinsavenue

    (@collinsavenue)

    No, unfortunately not. Tried that.
    Also tried deleting <option value=””>–</option> so that my form would be visible by default when I open post but that’s only cosmetic, it does not save the option to database. Only when I click save.

    Thread Starter collinsavenue

    (@collinsavenue)

    Oh noo, you were right, there was another settings page where I can set my form as a fallback if no forms found. Works fine now. Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Set default WPUF Form in posts.’ is closed to new replies.