Support

Account

Home Forums Front-end Issues [Badly Need Help] Post not pushing the category

Helping

[Badly Need Help] Post not pushing the category

  • Im trying to get my form to push the text from a textfield to set it as the category

    here is my code

    
    function category_textfield( $post_id ) {
    
        // Bail early if no ACF data
        if( empty($_POST['acf']) ) {
            return;
        }
        //array of category id's
        $categoryIds = array();
    
         //value of 'date' field is the cat_id
        $cataname = get_field('set_category');
        array_push($categoryIds, $cataname);
    
        wp_set_post_categories($post_id, $categoryIds);
    
    }
    add_action( 'acf/save_post', 'category_textfield' );

    but it doesnt seem to work, any suggestions

  • Hi @renshaw

    Kindly have a look at the Pre save hook in acf

    https://www.advancedcustomfields.com/resources/acfsave_post/

    Hopefully this helps.

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

The topic ‘[Badly Need Help] Post not pushing the category’ is closed to new replies.