Tag Info

Hot answers tagged

4

Right there is no big difference between them, actually wp_set_post_terms() uses wp_set_object_terms() but does few extra check for you. That's also noted on wp_set_object_terms() Codex page: Perhaps the wp_set_post_terms() is a more useful function, since it checks the values​​, converting taxonomies separated by commas and validating hierarchical ...


3

The plugin Term Management Tools will allow you to merge tags.


3

So, to answer my own question: I haven't found any solution inside wp_insert_post_data. I suspect that the problem is connected to the fact that when wp_insert_post_data is executed the post in question is not yet in the database. And albeit I didn't manage to find it in taxonomy.php, it is logical to assume that the wp_set_post_terms function have some ...


3

You should hook onto the save_post action. add_action( 'save_post', 'add_video_taxonomy' ); function add_video_taxonomy( $post_id ) { // you should check if the current user can do this, probably against publish_posts // you should also have a nonce check here as well if( get_post_meta( $post_id, 'video_url', true ) ) { ...


3

The fourth parameter to wp_set_object_terms() is an "append" argument. $append (bool) (required) If true, tags will be appended to the object. If false, tags will replace existing tags Default: False http://codex.wordpress.org/Function_Reference/wp_set_object_terms Your code should work if you pass true as that fourth argument. ...


2

So long as you're in the loop, you can just use the standard template tags: <script type="text/javascript" charset="utf­8"> initFrame({ app_id: "", object_id: <?php the_ID() ?>, object_title: "<?php the_title_attribute() ?>", object_content: '<?php echo wp_trim_words( strip_shortcodes( striptags( ...


2

You can pass an array of terms to wp_set_object_terms, there is no need for the for each: $genres= array('action', 'comedy', 'horror'); $ret = wp_set_object_terms( $postId, $genres, 'genres');


2

When you create a term for a hierarchical taxonomy, if you don't specify a parent, its parent ID is set to 0. In other words, it becomes a parent term. Edited with regards to comments: Add specifically each term you wish to add to the post (parent terms aren't automatically added if their children are). Adding terms to posts does not effect the terms ...


1

I asked the same question a while ago. Scribu gave me an answer here. The long and short of it: after you insert your terms, add this line of code. delete_option("my_custom_taxonomy_children"); Of course, replace my_custom_taxonomy with your own, but leave the _children part.


1

Use wp_is_post_revision() function which will give you false if post is not a revision (in which case just work as usual with that) or actual post ID to use instead of revision's.


1

Since wp_set_post_terms() does not accept hierarchy for it, you will first have to check if terms exist already, create them using wp_insert_term() if not and only then assign to post. Note that there had been (don't know current state) some cache related bugs with doing such things on the fly, see Inserting terms in an Hierarchical Taxonomy


1

Change the name of the checkboxes fromfirm to firm[]. Then, when you go to save the checkboxes $terms = $_POST['firm']; will give you an array of term slugs that can be checked/sanitized prior to using wp_set_object_terms to add the terms... wp_set_object_terms( $user_id, $terms, 'firm', false);


1

Forget about the previous answer, You say that it works fine with publish_post hook then you create a plugin in your mu-plugins (“must-use” plugins) which you can hook your function to and just add switch_to_blog before you start inserting and updating things in the database and then revert back using restore_current_blog() So ...


1

Dealing with terms is known to be very heavy operation. The common tweak recommended is to use wp_defer_term_counting() to temporarily disable updating of terms count (which is stored persistently in database and so must be updated when you change terms).


1

The last (fourth) argument that you pass to wp_set_object_terms() is true, which, "If true, tags will be appended to the object. If false, tags will replace existing tags". It sounds as though you are instructing wp_set_object_terms() to do, if I understand you, exactly what you don't want it to do. I think that you need to set the last argument to false or ...


1

you need to make an array from comma separated string of keywords like $keywords = explode(',', $keywords); then your insert post data array will be. $new_post = array( 'post_title' => $title, 'tax_input' => array( 'keyword' => $keywords ), 'post_status' => 'publish', 'post_type' => 'test' );


1

I think you have used wrong tax_input parameter value for wp_insert_post() function it should be array like this array( 'taxonomy_name' => array( 'term', 'term2', 'term3' ) ) as shown in the following code $my_post = array( 'post_title' => $title, 'post_content' => $content, 'post_status' => 'publish', ...


1

This is a stab in the dark, but have you tried using the set_object_terms hook for your bam_save_event_cat function? function bam_save_event_cat( $post_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) { $taxonomy = 'categoria'; $tribe_cats = get_the_terms( $post_id, 'tribe_events_cat'); foreach($tribe_cats as $tribe_cat) { if( ...



Only top voted, non community-wiki answers of a minimum length are eligible