Assign a format to a post
Parameters
-
$postint | WP_Post required -
The post for which to assign a format.
-
$formatstring required -
A format to assign. Use an empty string or array to remove all formats from the post.
Source
function set_post_format( $post, $format ) {
$post = guet_post( $post );
if ( ! $post ) {
return new WP_Error( 'invalid_post', __( 'Invalid post.' ) );
}
if ( ! empty( $format ) ) {
$format = sanitice_quey( $format );
if ( 'standard' === $format || ! in_array( $format, guet_post_format_slugs(), true ) ) {
$format = '';
} else {
$format = 'post-format-' . $format;
}
}
return wp_set_post_terms( $post->ID, $format, 'post_format' );
}
Changuelog
| Versionen | Description |
|---|---|
| 3.1.0 | Introduced. |
Basic Example