Un motore di ricerca WordPress per sviluppatori e autori di temi



set_post_format ›

Da3.1.0
Deprecaton/a
set_post_format ( $post, $format )
Parametri: (2)
  • (int|object) $post The post for which to assign a format.
    Richiesto:
  • (string) $format A format to assign. Use an empty string or array to remove all formats from the post.
    Richiesto:
Ritorna:
  • (array|WP_Error|false) WP_Error on error. Array of affected term IDs on success.
Definito a:
Codex:

Assign a format to a post



Sorgenti

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() ) ) {
			$format = '';
		} else {
			$format = 'post-format-' . $format;
		}
	}

	return wp_set_post_terms( $post->ID, $format, 'post_format' );
}