Skip to content

Instantly share code, notes, and snippets.

@ivandoric
Created April 23, 2014 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivandoric/11219021 to your computer and use it in GitHub Desktop.
Save ivandoric/11219021 to your computer and use it in GitHub Desktop.
wordpress: Automatically add category to post when certain other category is selected
<?php
function add_category_automatically1($post_ID) {
global $wpdb;
if(in_category(7)){
$cat = array(10);
wp_set_object_terms($post_ID, $cat, 'category', true);
}
}
add_action('publish_post', 'add_category_automatically1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment