Support

Account

Home Forums General Issues Set category using text field

Solving

Set category using text field

  • How would i go about making it so a text field can set the posts category ?

    add_action( 'acf/save_post', 'category_by_text', 10 );
    function category_by_text( $post_id ) {
    
        // Bail if not logged in or not able to post
        if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
            return;
        }
    
        // Bail early if no ACF data
        if( empty($_POST['acf']) ) {
            return;
        }
    
        // ACF image field key
        $catatext = $_POST['acf']['field_551c9469b244c'];
    
        // Bail if image field is empty
        if ( empty($catatext) ) {
            return;
        }
    
        // Add the value which is the image ID to the _thumbnail_id meta data for the current post
        add_post_meta( $post_id, 'category', $catatext );
    
    }

    so far i have this, but it doesn’t work. am i going about it completely wrong?

  • The support for this plugin is next to none, i regret buying it! what a joke.

  • This reply has been marked as private.
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Set category using text field’ is closed to new replies.