Articles of wp set object terms

Wp set post terms not work

My code is not working, it does not add the taxonomy add_action(‘init’, ‘post_test’, 10); function post_test() { $empty = get_page_by_title(‘Produto teste’, OBJECT, ‘produtos’); if(empty($empty)) { $insert_post = array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘produtos’, ‘post_title’ => ‘Produto teste’, ); $post_id = wp_insert_post($insert_post); if ($post_id) { wp_set_post_terms($post_id, array(‘metais’), ‘categoria-produtos’); // tag metais id is 108 } […]

What are terms and taxonomy, how they related to post and how these three are stored in database?

I want to understand terms and taxonomy in WordPress. My questions: What are the terms and taxonomy in wordpress? How terms and taxonomy relates to post and how post, terms, taxonomy are stored in database ? What is the relationship between these three ? My actual problem: I have a site of real estate agency, […]

Programmatically insert hierarchical terms & set terms for post causes glitch?

This question already has an answer here: Inserting terms in an Hierarchical Taxonomy 5 answers

Automatically assign taxonomy term if custom meta value exists

I currently have a custom meta field for adding a video url to the post. I’d like for the existing taxonomy term “video” to be automatically assigned to the post upon saving if the meta field has any value.

wp_set_object_terms() Fails to Set Terms

Okay guys, here’s the scenario. I’m am trying to setup a function that will automatically duplicate a post (when published) over to another post type. So, a regular blog post is published, and when it is published, all of its information is copied over to a custom post type (for WP ECommerce), automatically creating a […]

wp_set_object_terms() is not replacing term, but creating a new one

From a custom Submenu Page if I use a hard code like: $post_id = 111; $flightCategory = array( 25 ); wp_set_object_terms( $post_id, $flightCategory, ‘flight_categories’ ); And refresh the page, it simply assigns the desired Custom Taxonomy Terms to the CPT. But if I proceed with the following code, where I’m taking the values from a […]

wp_set_object_terms creates relationship to REVISION?

I have a custom post type, ‘albums’. In it is a taxonomy, ‘album_artist’. I am trying to programatically add artists to that taxonomy using wp_set_object_terms in a function that’s hooked into save_post. function get_album_data($post_id) { // CODE REMOVED FOR BREVITY: IMPORT DATA FROM EXTERNAL SOURCE, PARSE VARS wp_set_object_terms( $post_id, $album_artist_name, ‘album_artist’, true ); update_post_meta ($post_id, […]

How can I add programmatically custom taxonomy terms to a custom type post when saving posts?

Scenario: there is a ‘Recommended Books’ section on the website which uses the ‘book’ custom post type and the ‘author’ custom taxonomy. I’m using Amazon Product Advertising API for retrieving book data and covers. When adding a new ‘book’ into WordPress, the user copies the book ID (ASIN) into the post edit field, and clicks […]

Send an email when custom post type category is changed

This is the first time I’ve attempted to write an action hook. My CPT has 4 categories. I’m trying to make WP automatically sends an email notification when the category is changed. By change I mean: Let’s say the post has a category of “cat1”. The admin unselects cat1 and selects “cat2” and then clicks […]

wp_set_object_terms and arrays

I need to add a category to about 2500 posts, and either need to use an SQL query or wp_set_object_terms with PHP. I’m looking at wp_set_object_terms so I can add a category and not impact the currently assigned categories. The function below that uses wp_set_object_terms’ (from the WordPress Codex) adds one or more categories from […]