function set_post_format( $post, $format ) {}

Assign a format to a post


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

Return values

returns:WP_Error on error. Array of affected term IDs on success.

Source code

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, array_keys( get_post_format_slugs() ) ) )

			$format = '';


			$format = 'post-format-' . $format;


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



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: