Skip to content

Instantly share code, notes, and snippets.

@stephanieleary
Created August 4, 2016 14:20
Show Gist options
  • Save stephanieleary/f767a4b135f85809de7fc3f74e7ee1ab to your computer and use it in GitHub Desktop.
Save stephanieleary/f767a4b135f85809de7fc3f74e7ee1ab to your computer and use it in GitHub Desktop.
Add explicit categories to HTML Imported posts
<?php
// [file fragment]
// find this, around line 671
// ... and all the taxonomies...
$taxonomies = get_taxonomies( array( 'public' => true ), 'objects', 'and' );
foreach ( $taxonomies as $tax ) {
if ( isset( $options[$tax->name] ) )
wp_set_post_terms( $post_id, $options[$tax->name], $tax->name, false );
}
if ( isset( $customfieldtags ) )
wp_set_post_terms( $post_id, $customfieldtags, 'post_tag', false );
// add this on a new line:
wp_set_post_terms( $post_id, 'category-ID', 'category', false );
// note that false replaces existing categories. Change to true to append instead.
// Category IDs can be single, or an array or comma-separated string
// see https://codex.wordpress.org/Function_Reference/wp_set_post_terms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment