Support » Plugins » Add post categories via post form.

  • 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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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?

    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.

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add post categories via post form.’ is closed to new replies.