wp_set_post_categories [ WordPress Function ]
wp_set_post_categories ( $post_ID = 0, $post_categories = array() )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Similar Functions: wp_get_post_categories, wp_set_post_cats, wp_set_post_terms, wp_list_categories, wp_get_post_cats
Set categories for a post.
If the post categories parameter is not set, then the default category is going used.
Source
<?php
function wp_set_post_categories($post_ID = 0, $post_categories = array()) {
$post_ID = (int) $post_ID;
$post_type = get_post_type( $post_ID );
$post_status = get_post_status( $post_ID );
// If $post_categories isn't already an array, make it one:
if ( !is_array($post_categories) || empty($post_categories) ) {
if ( 'post' == $post_type && 'auto-draft' != $post_status )
$post_categories = array( get_option('default_category') );
else
$post_categories = array();
} else if ( 1 == count($post_categories) && '' == reset($post_categories) ) {
return true;
}
if ( !empty($post_categories) ) {
$post_categories = array_map('intval', $post_categories);
$post_categories = array_unique($post_categories);
}
return wp_set_object_terms($post_ID, $post_categories, 'category');
}
?>
Examples [ wp-snippets.com ]
Top Google Search Results
- Function Reference/wp set post categories « WordPress Codex
Description. Set categories for a post. If the post categories parameter is not set, the default category will be used. You can also use the extended method ...
codex.wordpress.org - WordPress › Support » Tags — wp_set_post_categories
Forums. Username or Email Address Password (forgot?) Register · WordPress › Support » wp_set_post_categories. Tag: wp_set_post_categories Add New » ...
wordpress.org - How to update post cat before save_post (wp_set_post_categories ...
Posted 2 years ago #. Hey guys,. I'm trying to update categories of a post based on input in custom fields but wp_set_post_categories only works when the post ...
wordpress.org - wp_set_post_categories (WordPress Function) - WPSeek.com
WordPress lookup for wp_set_post_categories, a WordPress Function. wpseek. com is a WordPress-centric search tool for developers and theme authors.
wpseek.com
User discussions [ wordpress.org ]
- Brayne on "Problem with wp_insert_post for custom post type - category is not associated"
- wrk on "Problem with wp_insert_post for custom post type - category is not associated"
- DDT on "Problem with wp_insert_post for custom post type - category is not associated"
- Mark / t31os on "Problem with wp_insert_post for custom post type - category is not associated"
- Christiann on "Problem with wp_insert_post for custom content type"
- Christiann on "Problem with wp_insert_post for custom post type - category is not associated"
- Christiann on "Problem with wp_insert_post for custom content type"
- Christiann on "Problem with wp_insert_post for custom content type"
- robanna on "How to update post cat before save_post (wp_set_post_categories only works once"
- bsieders on "How to update post cat before save_post (wp_set_post_categories only works once"