please help me
i’m using:
$wpdb->insert( $wpdb->term_relationships,
array( 'object_id' => $object_id, 'term_taxonomy_id' => $id ) );
and also:
$wpdb->query("INSERT INTO ".$wpdb->term_relationships."
(object_id, term_taxonomy_id) VALUES ($object_id, $id)");
but it doesn’t work, it adds nothing to the db
what can i do?
I had a similar problem:
wp_set_post_categories($wpdb->insert_id, array($req->wpcat));
wp_set_post_tags($wpdb->insert_id, $tags);
wp_set_post_categories uses the $wpdb object to insert, thus changing the insert ID.
I fixed it by doing this:
$post_ID = $wpdb->insert_id;
wp_set_post_categories($post_ID, array($req->wpcat));
wp_set_post_tags($post_ID, $tags);
This works as of 2.7.0.
Hope someone finds this helpful.
Reminder: $tags holds a single dimensional array. Ex:
$tags = array('one', 'two', 'three');
I’m using this and it works with WP 2.8.4
the $id is Post id.
function write_tags($id, $tags) {
$taxonomy = ‘post_tag’;
//$tags = split(” “,$months);
$tags = explode(‘ ‘, $tags);
foreach ($tags as $solotag) {
$solotag = trim($solotag);
$check = is_term($solotag, $taxonomy);
if (is_null($check)) {
$tag = wp_insert_term($solotag, $taxonomy);
if(!is_wp_error($tag)) {
$tagid = $tag[‘term_id’];
} else {
$tagid = $check[‘term_id’];
}
// wp_set_object_terms($id, $tagid, $taxonomy, true);
}
}
wp_set_post_tags($id,$tags);
}
hope this will help someone cause i need it wery much and finally i did it 🙂