How can I auto tag attachments based on the post?
-
Lets say I would like to create one Media category for each post,
And let the code auto update the list,
I tried something like (just to create the categorie, I’ll figure how to set the attachments later):
$parent_term = term_exists( $thePropTitle, 'attachment' ); // array is returned if taxonomy is given $parent_term_id = $parent_term['term_id']; // get numeric term id if ($parent_term !== 0 && $parent_term !== null) { echo 'nye<br>'; }else{ echo 'yay? '.$parent_term_id.'/'.$thePropTitle.'/<br>'; wp_insert_term( $thePropTitle, // the term 'attachment', // the taxonomy array( 'description'=> 'Tagged to '. $thePropTitle.'.', ) ); } $parent_term = term_exists( $thePropTitle, 'attachment' ); $parent_term_id = $parent_term['term_id']; echo 'term:' . $parent_term_id;
But the item is not added to the media categories..
I believe the taxonomie name (attachment) that i’m using is incorrect?
Anybody tried to Do something like this? or knows what am I missing here?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How can I auto tag attachments based on the post?’ is closed to new replies.