Last active
August 13, 2020 22:01
-
-
Save polevaultweb/01fa8aad1c4e4571b7513c08111aaca1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'igp_image_post_taxonomy_terms', 'first_tag_to_category', 10, 4 ); | |
function first_tag_to_category( $terms, $image, $post_id, $taxonomy ) { | |
$tags = isset( $image->tags ) ? maybe_unserialize( $image->tags ) : array(); | |
if ( empty( $tags ) ) { | |
return $terms; | |
} | |
$first_tag = reset( $tags ); | |
$term = get_term_by( 'name', $first_tag, $taxonomy ); | |
if ( ! $term ) { | |
$term = wp_insert_term( ucfirst( $first_tag ), $taxonomy ); | |
$term_id = $term['term_id']; | |
} else { | |
$term_id = $term->term_id; | |
} | |
$terms[0] = $term_id; | |
return $terms; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment