Code: Alles auswählen
// Add a category to a post for each of selected tags the post already has.
// Modify the $tag_categories array. Use one tag name => one category name
function mam_add_category ($post_id = 0) {
if (!$post_id) return;
$tag_categories = array ( // The tag names and the corresponding category name to add
'info' => 'information',
'INFO' => 'information',
'search optimization' => 'SEO',
);
$post_tags = get_the_tags($post_id);
foreach ($post_tags as $tag) {
if ($tag_categories[$tag->name] ) {
$cat_id = get_cat_ID($tag_categories[$tag->name]);
if ($cat_id) {
$result = wp_set_post_terms( $post_id, $tags = $cat_id, $taxonomy = 'category', $append = true );
}
}
}
}
add_action('publish_post','mam_add_category');
?>
Danke schonmal für jeden Tipp