set_post_format
函数
set_post_format ( $post, $format )
- 参数
-
-
(int|object)
$post
The post for which to assign a format.- Required: 是
-
(string)
$format
A format to assign. Use an empty string or array to remove all formats from the post.- Required: 是
-
(int|object)
- 返回值
-
- (array|WP_Error|false) Array of affected term IDs on success. WP_Error on error.
- 定义位置
-
-
wp-includes/post-formats.php
, line 70
-
wp-includes/post-formats.php
- 引入
- 3.1.0
- 弃用
- –
Assign a format to a post
function set_post_format( $post, $format ) { $post = get_post( $post ); if ( ! $post ) { return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); } if ( ! empty( $format ) ) { $format = sanitize_key( $format ); if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs(), true ) ) { $format = ''; } else { $format = 'post-format-' . $format; } } return wp_set_post_terms( $post->ID, $format, 'post_format' ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。