set_post_format() – Assign a format to a post

You appear to be a bot. Output may be restricted

Description

Assign a format to a post

Usage

$array|WP_Error|false = set_post_format( $post, $format );

Parameters

$post
( int|object ) required – The post for which to assign a format.
$format
( string ) required – A format to assign. Use an empty string or array to remove all formats from the post.

Returns

array|WP_Error|false Array of affected term IDs on success. WP_Error on error.

Source

File name: wordpress/wp-includes/post-formats.php
Lines:

1 to 18 of 18
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' );
}
 

 View on GitHub View on Trac