Switch language

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




set_post_type [ WordPress Function ]

set_post_type ( $post_id = 0, $post_type = 'post' )
Parameters:
  • (int) $post_id Post ID to change post type. Not actually optional.
  • (string) $post_type Optional, default is post. Supported values are 'post' or 'page' to name a few.
Uses:
  • $wpdb
Returns:
  • (int) Amount of rows changed. Should be 1 for success and 0 for failure.
Defined at:



Updates the post type for the post ID.

The page or post cache will be cleaned for the post ID.

Source


<?php
function set_post_type$post_id 0$post_type 'post' ) {
    global 
$wpdb;

    
$post_type sanitize_post_field('post_type'$post_type$post_id'db');
    
$return $wpdb->update$wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );

    
clean_post_cache$post_id );

    return 
$return;
}
?>

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