Few points come to mind:
-
There is a typo in
"post_type" => "'eyeglasses"(extra single quote). It should be:"post_type" => "eyeglasses". -
Try putting the
$terminstead ofarray( $term ):"tax_input" => array( "models" => $term ) -
Also, is it
modelsormodel? e.g."tax_input" => array( "model" => $term ) -
tax_inputrequiresassign_termscapability. So if the user you are running this CODE with, doesn’t have that capability, it’ll not work.In that case, the right way is:
$post_id = wp_insert_post(array( "post_type" => "eyeglasses", "post_title" => $title, "post_status" => "publish" )); wp_set_object_terms( $post_id, $term, 'model' );
Related Posts:
- install.php Custom Taxonomy Term not being added to custom post
- Get terms by taxonomy AND post_type
- Get Posts by Custom Post Type ,Taxonomy, and Term
- Display current taxonomy term when inside custom post type
- Get term slug of current post
- How do I list custom taxonomy terms without the links?
- query multiple taxonomies
- wp_set_object_terms() is not replacing term, but creating a new one
- Get terms that contain posts that in turn belong to other terms?
- wp_insert_term doesn’t work with custom post type’s taxonomy
- wp_get_object_terms(): count relative to passed IDs?
- array_pop() expects array, boolean given for $event_type_term ->slug
- Custom Post Type Archive Template
- Maintaining strict one-to-one association between terms and custom posts
- If on term-page -> get the current term?
- wp_insert_post custom taxonomy
- Get list of terms of current taxonomy archive for another taxonomy
- Creating a function that receives the taxonomy terms that have been changed in a custom post type
- Get all taxonomies for all post types
- Dynamically create/remove terms in taxonomy when custom post type is published/trashed
- How do I provide a “show all posts” link in a paginated term archive?
- WordPress tax_input only if logged in
- How to filter the taxonomy terms based on another taxonomy term
- How to get posts from multiple custom post types according to it’s custom taxonomy terms?
- How to output wordpress custom tags separated by comma?
- Displaying a custom post types custom taxonomy value?
- get_the_terms return only last term
- Does WordPress limit the length of slug names for Post Meta or Terms?
- get_post_meta returns empty array for terms
- Custom Post Type Archive Page Filtering
- Filtering WP_Query Dynamically on the Front-End
- Get posts by querying taxonomy and certain terms of the taxonomy?
- Displaying custom taxonomy in the admin list of a custom post type
- Display post as term id
- Post count by month of taxonmy term
- How to checked selected category checkbox when my custom post inserted from frontend
- How do I display the taxonomy for a custom post type in an array
- Display Custom Taxonomy Alphabetically
- Get terms that contain posts that in turn belong to other terms?
- Custom while loop for hierarchical display of a taxonomy
- Lists custom taxonomy terms that has specific custom field value assigned to the term (not post)
- Display taxonomy terms, child terms and posts in a template
- Use custom walker to add taxonomy terms to main nav menu
- Add term to custom post type on draft
- Displaying custom-taxonomy-terms sorted by parent/child-hierarchy?
- Listing all term items alphabetically / sorting loop
- Query posts with double taxonomy
- Why cant I add a custom post type to a custom taxonomy?
- Adding predefined terms to a taxonomy
- Custom query – get_the_terms not work
- Custom Post Types Archives and Single Pages not showing custom taxonomy data
- Shared terms between taxonomies
- How to get dropdown instance value in WordPress custom Widget
- Get taxonomy term by slug in post on archive page
- custom hierarchical taxonomy and custom post type list contains surplus posts
- How to display custom taxonomy term meta on custom post type
- get_terms() returns Trying to get property of non-object error for custom taxonomy
- how to count the current posts terms
- Urls in Custom Post Type work for Terms but not for its Taxonomies
- does wp_insert_term link the term to a certain post ID?
- Custom Taxonomy Terms in Menu lead to which page?
- Add custom post type taxonomy tag to article class
- Custom Taxonomy dont save in a frontend form for post a custom post
- Add filter to Admin list for all custom post types by their custom taxonomies
- Add the custom post term to the custom post title
- Retrieve Custom Taxonomies with Description and Slug
- How to list posts by term (custom taxonomy)
- Custom taxonomy not saving correctly
- Taxonomy terms with the same name are updated between separate custom post types
- Add a class to a div if custom post type has specific terms?
- Return multiples taxonomies with wp_get_object_terms
- Custom taxonomy terms hierarchical navigation
- How to list posts by terms
- Excluded Custom Taxonomy Term Posts Displaying in loop
- How to order taxonomy terms by most recent post?
- Saving Child Terms on front end not setting parent
- How to show terms used only for particular custom post type. Filter creation perpose
- Custom taxonomy- only output relevant terms
- order taxonomy alphabetical
- Filter Term By Parent Term – Custom Post Type
- Display all Custom taxonomy terms and their relevant custom posts
- WordPress get all post with like in terms [duplicate]
- Decrement term in for each
- Best way to group posts based on custom post type terms
- Get list of CPT posts in *current* post’s taxonomy term
- Prevent repetitive terms in get_the_term_list
- How to retrieve the permalink for a specific (custom) term?
- Exclude Custom Post Type from shared Custom Taxonomy
- Remove Custom Taxonomy Slug only without removing Custom post type slug in permalinks
- Get a list of categories ids
- Get term_id for each instance of custom taxonomy
- List a custom taxonomy’s terms, with links, on the taxonomy page
- taxonomy terms array not working
- get_the_term_list() wanting to loop through the returned values
- show 10 most recent custom post types excluding the one(s) from specific custom taxonomy
- How to Get The Taxonomy Term in Custom Post Type Loop Inside a Wp Query
- Get term link of shared taxonomy between multiple post types
- How to use wp_set_object_terms depending on page ID?
- How to list custom taxonomy terms without the hyperlinks?
- Can’t retrieve custom post type taxonomy term to custom post type editor