WordPress.org

Ready to get started?Download WordPress

Forums

WP User Frontend
Set post_format when adding post? (3 posts)

  1. absurdo
    Member
    Posted 2 years ago #

    Is it possible to set post_format when adding post?

    http://wordpress.org/extend/plugins/wp-user-frontend/

  2. adaldesign
    Member
    Posted 1 year ago #

  3. adaldesign
    Member
    Posted 1 year ago #

    I was finally able to create a drop down to set post format using the hooks provided by Tareq and wanted to share my code in case it can be of use to anyone.

    Paste the following in your functions.php

    // Add the drop-down (you can edit the list of post format options)
    function wpufe_content_type( $post_type, $post = null) {
    
        ?>
        <li>
            <label for="post_format">Content Type<span class="required">*</span></label>
            <select class="requiredField" name="content_type" id="content_type">
            	<option value="" selected="selected">What are you posting?</option>
                <option value="standard">Text (Blog Post)</option>
                <option value="image">Single Image</option>
                <option value="gallery">Gallery of Images</option>
                <option value="video">Video</option>
                <option value="audio">Audio</option>
            </select>
            <div class="clear"></div>
        </li>
        <?php
    }
    
    add_action( 'wpuf_add_post_form_top', 'wpufe_content_type', 10, 2 );
    
    // Validate the data (optional)
    function wpufe_content_type_validation( $errors ) {
        if( $_POST['content_type'] == '' ) {
            $errors[] = 'Please select a Content Type.';
        }
    
        return $errors;
    }
    add_filter( 'wpuf_add_post_validation', 'wpufe_content_type_validation' );
    
    // Make it happen!
    function wpufe_add_content_type( $post_id ) {
    	set_post_format( $post_id, $_POST['content_type'] );
    }
    add_action( 'wpuf_add_post_after_insert', 'wpufe_add_content_type' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic