Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




set_post_format [ WordPress Function ]

set_post_format ( $post, $format )
Parameters:
  • (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.
Returns:
  • (mixed) WP_Error on error. Array of affected term IDs on success.
Defined at:



Assign a format to a post

Source


<?php
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$formatarray_keysget_post_format_slugs() ) ) )
            
$format '';
        else
            
$format 'post-format-' $format;
    }

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

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics