Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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