是否可以创建与此类似的功能
function add_category_automatically($post_ID) {
global $wpdb;
$postsWeWants = $wpdb->get_results("SELECT ID, post_author FROM $wpdb->posts where ID = $post_ID");
foreach ($postsWeWants as $postsWeWant) {
if(($postsWeWant->post_author != 30) && ($postsWeWant->post_author != 29) && !in_category('bundle')){
$cat = array(9547,9742);
wp_set_object_terms($post_ID, $cat, 'category', true);
}
}
}
add_action('publish_post', 'add_category_automatically');
但是基于post class而不是作者和类别?
答案 0 :(得分:0)
这样的事情应该可以解决问题:
function add_category_by_class($post_ID) {
if( in_array( 'classToCheckFor' get_post_class('', $post_ID)) ){
$cat = array(9547,9742);
wp_set_object_terms($post_ID, $cat, 'category', true);
}
}
add_action('publish_post', 'add_category_by_class');