I have created a few custom post types:
Each time I create a post I have to set the category (I am using categories to filter and place my posts on my home page). The category names are the same as the custom post type
What I want to do is, once the post is published it is automatically added to the right category.
I have seen this code, but I don’t fully understand it so don’t know how to customise it to my needs:
$category_ids = array(4, 5, 6);
wp_set_object_terms( $post_id, $category_ids, 'category');
This goes in the functions.php file
I would be very grateful if you could shed some light on how to achieve this.
- The topic ‘Set category to a custom post type automatically’ is closed to new replies.