WordPress.org

Ready to get started?Download WordPress

Forums

Add post categories via post form. (4 posts)

  1. mistycabal
    Member
    Posted 5 years ago #

    Basically I'm working up a site that builds in a posting form on a page. (Yes, I've tried TDO mini forms and I really need some more flexibility before and after the form than it offers). If you need a visual, think of the Prologue theme posting box with more info added.

    While I can get the rest of the form working, I'm totally getting lost in the php to get the categories working. It should function like it does on the backend with checkboxes. Populating and creating the checkbox list isn't the problem, it's looping through, converting to the id's, and figuring out how to format that into an array to send to wp_insert_post is where I'm getting caught up.

    I've got everything else working... titles, tags, custom fields, etc... just can't get the cats right for some reason. I think I've hit the braindead stage and need to get some outside input.

  2. adam.codefor
    Member
    Posted 5 years ago #

    I am also trying to do this with no look. I am trying to add additional custom fields and images. How did you get the custom fields and title etc?

  3. adam.codefor
    Member
    Posted 5 years ago #

    Ok sorted the title, custom fields and categories. For the categories I know you where looking for checkboxes but a drop down is really simple. I included the following in my form:

    <?php wp_dropdown_categories('hide_empty=0&title_li=&name=cat&hierarchical=1&exclude=1'); ?>

    To show a drop down of categories. (If you want more than one, maybe just repeat the drop down?)

    Then in my header (on form submit) I used the following:

    $category = $_POST['cat']; to get the category value from the drop down

    $category_array = array($category); to store the category as an array

    $post_id = wp_insert_post( array(
    		'post_author'	=> $user_id,
    		'post_title'	=> $post_title,
    		'post_content'	=> $post_content,
    		'post_category' => $category_array,
    		'tags_input'	=> $tags,
    		'post_status'	=> 'publish'
    	) );

    to push $category_array and co as a post.

    Hope that helps. Still not cracked image attachments yet - so any help would be great. I'll post back if I find anything.

  4. dlopeman
    Member
    Posted 4 years ago #

    AHHHH - yup - make it work with images! Good Luck.

Topic Closed

This topic has been closed to new replies.

About this Topic