1
        $page = array(
            'post_title'   => 'New Job',
            'post_name'    => 'new-job',
            'post_content' => '',
            'post_status'  => 'publish',
            'post_author'  => 1,
            'post_type'    => 'jobs',
            'tax_input'    => array (
                'status' => 'system'
            )
        );

        wp_insert_post( $page );

This doesn't work. I am trying to create post and relate it to my custom term in my custom taxonomy.

Taxonomy: status

Term: system

What am I doing wrong?

1

Turns out you can't use the term slug (for obvious reason of possible duplicate slugs face palm) you need to use the terms ID.

        $term_id = term_exists( 'system', 'status' );

        $page = array(
            'post_title'   => 'New Job',
            'post_name'    => 'new-job',
            'post_content' => '',
            'post_status'  => 'publish',
            'post_author'  => 1,
            'post_type'    => 'jobs',
            'tax_input'    => array (
                'status' => array ( (int)$term_id["term_id"] )
            )
        );

        wp_insert_post( $page );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.