set_post_format()
set_post_format( int|object $post, string $format ) 为文章…
set_post_format( int|object $post, string $format )
为文章指定格式
Assign a format to a post
目录锚点:#参数#源码#笔记
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $post | (int | object) | 指定格式的文章。 |
| $format | (string) | 要指定的格式。使用空字符串或数组从帖子中删除所有格式。 |
源码(Source)
/**
* Assign a format to a post
*
* @since 3.1.0
*
* @param int|object $post The post for which to assign a format.
* @param string $format A format to assign. Use an empty string or array to remove all formats from the post.
* @return array|WP_Error|false WP_Error on error. Array of affected term IDs on success.
*/
function set_post_format( $post, $format ) {
$post = get_post( $post );
if ( empty( $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() ) )
$format = '';
else
$format = 'post-format-' . $format;
}
return wp_set_post_terms( $post->ID, $format, 'post_format' );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 3.1.0 | wp-includes/post-formats.php | 18 | 20 |
笔记(Notes)
基本示例
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!