wp_set_post_categories()使用代码设置一篇文章的分类

目录

描述

译文

设置文章分类。

未设置文章分类参数时使用默认分类。

原文

Set categories for a post.

wp_set_post_categories() 描述

用法

<?php wp_set_post_categories$post_ID$post_categories$append ?>

wp_set_post_categories() 用法

参数

$post_ID

(integer) (可选) Post ID.

默认值: 0

$post_categories

(array) (可选) Array of category IDs.

默认值: array

$append

(boolean) (可选) If true, categories will be appended to the post. If false, categories will replace existing categories.

默认值: false

wp_set_post_categories() 参数

返回值

(boolean|mixed)

Returns an array of category IDs that were assigned to the post ID.

wp_set_post_categories() 返回值

注意

If no categories are passed with a post ID that has a post type of post, the default category will be used.

Be careful, as wp_set_post_categories will overwrite any existing categories already assigned to the post unless $append is set to true.

If an ID is passed with the categories array that is not associated with a valid category, it will be stripped before the object terms are updated and from the return array.

wp_set_object_terms() performs the same function with more granular control for built in categories and can also be used to set any custom taxonomies.

wp_set_post_categories() 注意

历史

添加于 版本: 2.1.0

wp_set_post_categories() 历史

源文件

wp_set_post_categories() 函数的代码位于 wp-includes/post.php.

wp_set_post_categories() 源文件

相关