When you remove vote check for your condition, then if needed:
- fetch categories with
wp_get_object_terms()
(low level func, you can specify to fetch names or ids only since you don’t need full objects for this) - modify array (remove category you don’t need, add the one you do)
- set categories with
wp_set_post_categories()
(it will overwrite all categories so those you remove from array will be gone)
Related Posts:
- Add options to featured image
- Change meta tags programatically
- Use a function to update post meta based on other post meta
- update_post_meta for custom field not working upon form submission
- Assign category using custom field?
- Convert User ID’s to User Names in a single.php file
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- What WordPress function to use to get meta value by using meta keys?
- Default Custom Field Value Automatically Update
- Post meta not updating
- Function to update post_meta based on existing post_meta
- Exclude from the query posts with meta_key and meta_value
- Prevent custom field from being updated after first publish
- Get array of metakey in all posts
- User function to return multiple get_post_meta()
- What are the meta fields for an attachment?
- How to avoid saving empty data to sql while using add_meta_box
- How to change text color depending on the number value (Using javascript)
- How to add custom metakey to shop_order page’s searching function?
- Update wp_postmeta table based on 2 keys
- blank page with wp_get_attachment
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- How To Display Author Popup on Entry Meta (Genesis Framework)?
- Creating a “Related Meta” type field?
- Remove post from latest posts after a month only with certain tag
- save_post doesn’t correctly process function call with php class
- Return ACF Field value function
- update_post_meta not working in function
- How To Get WordPress Categories Last Update Date?
- How to add a meta information to the URL?
- Automatically add custom fields (post_meta) to all published posts, hourly, via wp_cron?
- update_post_meta after form is submited
- Add custom fields after post/page title
- Display post_meta-by_key on product catalogue
- How to save custom made object in an array in a post meta field
- Adding and updating repeating custom field meta data
- Upload Multiple Files With media_handle_upload
- Add custom template page programmatically
- What is the difference between get_page_link and get_permalink functions?
- Woocommerce add to simple product attribute programmatically [closed]
- Breadcrumbs showing Parent and Child Pages
- mysql custom wp query
- TinyMCE custom stylesheets for different post types
- Order get_users() by last login date. Is it possible?
- Display random text from a file with the WP built-in AJAX API
- Function to Download External Images to My Site
- How to call a function on particular page like ‘contact-us’ from function.php of child theme
- Detect Safari desktop browser and include the detection in a shortcode
- Is It wrong to use oop approach on functions.php?
- How to preserve edits to Name or Slug of term when using wp_update_term on save?
- How Can I Expand the WordPress Customize window without any Plugin?
- Register and enqueue style.css custom theme
- Where do I add html code to the menu div?
- Add function to every post?
- Understanding and altering the structure of posted images
- What do the schemes login, login_post, admin, and relative mean?
- Product object returns no sale price
- How to stop twenty fifteen theme from cropping featured images?
- Option Tree integration of Custom CSS
- Deprecated function get_user_by_email($email)
- Don’t display html if function returns nothing
- Shortcode parse error – wrong syntax
- Load custom css in functions.php causing library issue
- In jquery use php variable to execute an enqueued jquery file
- Run a jquery script on on a certain template page
- How to stop media_sideload_image from running when deleting a post?
- I want to display latest post in marquee [closed]
- Can’t add_action to ‘save_post’ and get it to fire
- How to load jQuery in TOP of wp_footer?
- How to fetch custom post type by variable date?
- How to make custom comment fields required
- two search forms on the same page
- Getting out side of wp root folder from function.php using absolute path
- How do I register a new settings page? [closed]
- Include Jquery libraries in wordpress theme?
- Strange error from functions.php files (wp_register_script)
- Retrieve First Image Function
- User meta and public function security
- Display ACF category image on archive and single template files
- How to get taxonomy tree ids without running expensive loops
- Auto delete content in specific folder inside media library
- Using get_terms for custom taxonomy in functions.php
- How to update an image attachment’s alt text from a custom field when saving a post?
- Allow user only create specific tags
- Child theme remove parent filter in functions
- Set URL Parameter Post Layout As Default
- Enqueue JS + CSS via a child theme functions.php file?
- How to add publish/draft button in Admin Post Lists
- Woocommerce – change order status from on-hold to pending payment
- How to add number to wordpress count function?
- How do I integrate my Child Theme into a Custom Template?
- Sending Messages Back to the Template After Processing?
- Shortcode to eliminate and replace with
- Why are some custom javascript files working but some are not
- Postmeta not saving
- using enqueue_script in a shortcode isn’t working
- How to display milliseconds instead of seconds using timer_stop function? [closed]
- Filter to strip unnecessary attributes
- get_post_class() not working well
- How to overwrite image if it already exists – WordPress, Gravity form