Created
April 23, 2014 21:05
-
-
Save mch0lic/11232368 to your computer and use it in GitHub Desktop.
nimble_portfolio_register_taxonomies patch
This file contains 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
function nimble_portfolio_register_taxonomies() { | |
register_taxonomy('nimble-portfolio-type', 'portfolio', array('hierarchical' => true, 'label' => 'Item Type', 'query_var' => true, 'rewrite' => array('slug' => 'portfolio-type'))); | |
if (count(get_terms('nimble-portfolio-type', 'hide_empty=0')) == 0) { | |
register_taxonomy('type', 'portfolio', array('hierarchical' => true, 'label' => 'Item Type')); | |
$_categories = get_categories('taxonomy=type&title_li='); | |
foreach ($_categories as $_cat) { | |
if (!term_exists($_cat->name, 'nimble-portfolio-type')) | |
wp_insert_term($_cat->name, 'nimble-portfolio-type'); | |
} | |
// Clone $post object to restore it afterwards | |
global $post; | |
$post_clone = $post; | |
$portfolio = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => '-1')); | |
while ($portfolio->have_posts()) : $portfolio->the_post(); | |
$post_id = get_the_ID(); | |
$_terms = wp_get_post_terms($post_id, 'type'); | |
$terms = array(); | |
foreach ($_terms as $_term) { | |
$terms[] = $_term->term_id; | |
} | |
wp_set_post_terms($post_id, $terms, 'nimble-portfolio-type'); | |
endwhile; | |
// Restore original Post Data | |
$post = $post_clone; | |
// wp_reset_query(); // wp_reset_query is no longer needed | |
register_taxonomy('type', array()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment