Issue Assigning Custom Terms to New Post
-
I have a form in which I’m creating a new post using the af/form/submission/key=[form_key] action.
The form contains Taxonomy fields for multiple custom taxonomies – Document Type (select), Document Category (checkbox) and Document Tag (multi-select). All three are set to return Term ID.
For Document Type and Document Category I have disabled “Create New Terms” on the field, and they are saving correctly. However for the Document Tags I have enabled “Create New Terms” so that users can add new tags. This one is not saving correctly. When an existing tag is selected, for example “parking” which has an ID of 334, instead of assigning that tag, a new tag is created with the name “334” and slug “334”.
I think it is most likely caused by the “Create New Terms” option.
My code is as follows:
$doc_type = af_get_field('type'); $doc_cat = af_get_field('document_category'); $doc_tag = af_get_field('document_tags'); $custom_tax = array( 'document-type' => $doc_type, 'document-category' => $doc_cat, 'document-tag' => $doc_tag ); // Set initial post data from form fields $post_data = array( 'post_type' => 'document', 'post_status' => 'draft', 'post_title' => $document_title, 'post_content' => '', 'tax_input' => $custom_tax ); // Create post $post_id = wp_insert_post( $post_data );
Please advise.
Thank you
- The topic ‘Issue Assigning Custom Terms to New Post’ is closed to new replies.