Automatically set category based on wordpress post visibility? -
i've been looking way automatically append category everytime post set private. i've seen several of ways of doing custom post types i've yet figure out way how achieve post visibility.
any ideas?
this filter should job.
function add_categories_automatically($postid) { if(get_post_status($postid) == 'private'){ $catsid = array(5); wp_set_post_categories($postid, $catsid, true); } } add_action('publish_post', 'add_categories_automatically');
this check post status when published. if status private, specified categories appended post.
be careful, wp_set_post_categories overwrite existing categories assigned post unless third parameter set true: wp_set_post_categories
Comments
Post a Comment