Created
September 14, 2010 01:43
-
-
Save anthonycole/578395 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 | |
/** | |
* | |
* @package WordPress | |
* @subpackage Taxonomy | |
* | |
* @uses $wpdb | |
*/ | |
function set_term_taxonomy( $args ) { | |
global $wpdb; | |
$defaults = array( | |
'term_name' => '', | |
'new_taxonomy' => '', | |
'old_taxonomy' => '', | |
'children' => false, | |
); | |
wp_parse_args( $args, $defaults ); | |
extract( $args, EXTR_SKIP ); | |
if( empty( $term_name ) || empty( $new_taxonomy ) || empty( $old_taxonomy ) ) { | |
return new WP_Error('Required terms not specified', 'required-terms-not-specified'); | |
} | |
$sql = $wpdb->query( $wpdb->prepare( "UPDATE %s SET taxonomy='%s' WHERE term_id IN (SELECT term_id FROM %s WHERE slug LIKE \%%s\% AND taxonomy == %s)", $wpdb->terms_taxonomy, $new_taxonomy, $wpdb->terms, $old_taxonomy ) ); | |
if( true === $children ) { | |
$children = get_term_children( get_term( $term, $new_taxonomy ) ); | |
foreach( $children as $child ) { | |
$wpdb->query( $wpdb->prepare( "UPDATE %s SET taxonomy='%s' WHERE term_id == %s", $wpdb->terms_taxonomy, $newtax, $wpdb->terms, $oldtax ) ); | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment