Home Forums General Issues Categorize new post created using acf_form


Categorize new post created using acf_form

  • Hey there, I’d like to categorize and/or tag new posts created using acf_form.

    Ideally, a user would pick a category from a select menu I’ve included in a field group. Below is my code. Any thoughts?

    function my_pre_save_post( $post_id ) {
        if ( $post_id != 'new' ) {
            return $post_id;
        $post = array(
            'post_status' => 'draft',
            'post_title'  => $_POST['acf']['field_546f5d3ca98ab'],
            'post_category' => $_POST['acf']['field_546f5d3ca98ab'],
            'post_content' => $_POST['acf']['field_546f5d49a98ad'],
            'post_type' => 'post'
        $post_id = wp_insert_post($post); 
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
        return $post_id;
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );

    I’ve tried a few different things, including matching up the options with the category id:

    5 : Entertainment

    But no luck. Any ideas?

  • Any joy with working this out?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.