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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -