WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/set post type

Description

Updates the post type for the post ID.

The page or post cache will be cleaned for the post ID. @uses $wpdb.

Usage

<?php set_post_type$post_id$post_type ); ?>

Parameters

$post_id
(integer) (required) Post ID to change.
Default: 0
$post_type
(string) (optional) New post type name.
Default: post

Examples

<?php
$post_id = 15;
if ( set_post_type( $post_id, 'page'  ) ) {
  echo "Post #$post_id is now a Page";
} else {
  echo "Impossible to transform this post into a page";
}
?>

Return Values

(integer) 
Amount of rows changed. Should be 1 for success and 0 for failure.

Change Log

Since: 2.5

Source File

set_post_type() is located in wp-includes/post.php

Related

Post Types: register_post_type(), add_post_type_support(), remove_post_type_support(), post_type_supports(), post_type_exists(), set_post_type(), get_post_type(), get_post_types(), get_post_type_object(), get_post_type_capabilities(), get_post_type_labels(), is_post_type_hierarchical(), is_post_type_archive(), post_type_archive_title()

See also index of Function Reference and index of Template Tags.