The argument from pending_to_publish
action, $post_id
in your case, is not ID but array (callback to publish).
I think it would be better to use the publish_post
action, that way $post_id
will actualy be the post id.
Also this is a very general action so if you have multiple post types it would be wise to check if the current post type is the actual one you want to add the term to
Edited answer
Or in your case you can pass the post id as following
add_action('pending_to_publish', 'oj_publish_post');
function oj_publish_post($post) {
$taxonomy = 'category';
$term_id = array(8);
$term_id = array_map('intval', $term_id);
wp_set_post_terms( $post->ID ,$term_id, $taxonomy,true);
}
Related Posts:
- How to show a hierarchical terms list?
- tax_query in get_posts() not working?
- What is wp_insert_term “alias_of” arg for?
- Automatically Assign Parent Terms When A Child Term is Selected
- get term by id without taxonomy
- get a specific taxonomy term name
- List Hierarchical Term List with Count with Related Term
- Is there a way to set singular/plural labels for taxonomy term names?
- get_terms() How many is TOO many?
- get_terms with posts that have a different taxonomy with term x
- How to add terms to taxonomy with wp_insert_terms?
- Get_term_by only returns one item from array
- Can we have same term slug in different taxonomies?
- Is there any difference between post in child term and child & parent terms?
- Create and move terms for taxonomies
- Missing term_id and term_taxonomy_id when adding a term using wp_insert_term() function
- Count posts for each taxonomy term for each month
- What hooks/filters are there to alter selected terms on post save?
- How can I remove links from the function “get term list”?
- Get Term names from WP Term Object
- tax_query: What to pass when I want to have all terms?
- Add a term to an attachment submitted from front end
- functions to create term and child terms
- taxonomy/category term in URL slug irrelevant for post?
- How to use a Term Meta Field as a link
- what tables uses wp_get_post_terms
- WordPress built-in method to extract array of term IDs?
- How do I get the current tag out of a taxonomy?
- Variable in Array Not Working
- How to list 2 taxonomy terms for a post, based on their hierarchy
- Should I be using custom post types for this or terms and taxonomies?
- get_terms problem : related articles
- Why “Warning: Invalid argument supplied for foreach()”
- Order wordpress taxonomy parent terms by their children count
- WordPress User Taxonomy Saved Values
- get_the_terms error
- How can I find the taxonomy in edited_{taxonomy}?
- Use get_terms to get post_tags but limit to a taxonomy
- how to show only last child terms of a taxonomy
- How to get the top level parent term Advanced Custom Field values in the child terms
- Allow a Taxonomy Term to be Used Only Once Across All Posts
- Count Published & Draft Posts Associated With Each Term
- Ordering Taxonomies / Changing term_id
- Adding taxonomy terms based on custom field
- Multi Taxonomies same terms
- Make taxonomy terms appear in the order they were made
- get_the_term_list – Return links to edit.php instead of link to taxonomy archive template
- How to sync to custom taxonomies (tag structure)
- Comma separated tax terms, with “and” before last item [duplicate]
- the_terms characters not limiting
- `get_terms()` with `child_of` and `childless` combined
- Hierarchical list of custom taxonomy terms
- Add text to the end of each list item in wp_list_categories
- Return Taxonomy Name for Each Term
- echo term name outside the loop, using term slug
- Modify output of wp_dropdown_categories to add term IDs to each option
- How to return newly added terms when using wp_set_object_terms
- Blogroll links sorted by category in a table
- How to get terms from a custom taxonomies after WordPress 4.5.0
- How to update a taxonomy term for a custom post type with auto incrementing number
- How to relate a user object to taxonomy term?
- How to display taxonomy term custom meta (using wp_get_object_terms?)?
- Echo taxonomy name – second level
- If has_term, load other theme
- Get terms in hierarchical taxonomy
- Taxonomy Checkbox Admin Panel
- Retrieve all term IDs of post
- Related terms – Terms that feature in post of current term
- Bug using wp_insert_term with switch_to_blog
- how to list parent terms only
- update_term_meta not working
- Assign Multiple Values from Post Fields to Taxonomy Terms
- Checking if a product ID has taxonomy term attached not working with has_term
- Taxonomy.php inheriting first post
- Order custom taxonomy hierarchy
- I want to get term by term_name without taxonomy
- I want to change the slugs of my terms dynamically
- taxonomy terms, inverted
- echo a tax term in loop
- taxonomy_edit_form_fields output after term fields
- Create multidimensional array of taxonomies
- How to share terms between two taxonomies?
- $product->ID in has_term() not working, but manually inputting the ID works, why?
- Can I have have terms with the same slug in the same taxonomy?
- how do you get one specific term from a shortcode attribute?
- Get taxonomy url, name, post count & image
- Taxonomy terms can’t find posts from archive.php or taxonomy.php
- taxonomy terms are not populating select tag options
- What to do with shared terms splitting in WordPress 4.2?
- Related Posts by taxonomy using Advance Custom Fields Plugin
- How to filter the terms to a special custom taxonomy?
- GET Taxonomy ID
- Non-Recursive get_term_children()
- Display yesterday’s last post’s Custom field from Unique terms of one Taxonomies
- Delete Term via edit-tags.php
- Passing values by form to create a query
- Order taxonomy terms by the frequency of use in the last 30 days
- Why can’t I exclude a term ID from either get_terms or WP_Term_query?
- How to display a term of taxonomy
- get_terms of specific parent (including the parent itself)