wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



set_post_format › WordPress Function

Depuis3.1.0
Dépréciéen/a
set_post_format ( $post, $format )
Paramètres: (2)
  • (int|object) $post The post for which to assign a format.
    Requis: Oui
  • (string) $format A format to assign. Use an empty string or array to remove all formats from the post.
    Requis: Oui
Retourne:
  • (array|WP_Error|false) Array of affected term IDs on success. WP_Error on error.
Défini(e) dans:
Codex:

Assign a format to a post



Source

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' );
}