WordPress at a glance

set_post_type() WP 1.0

Update the post type for the post ID.

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

  • Global. wpdb. $wpdb WordPress database abstraction object.

No Hooks.

Return

Int/false. Amount of rows changed. Should be 1 for success and 0 for failure.

Usage

set_post_type( $post_id, $post_type );
$post_id(int)
Post ID to change post type.
Default: 0
$post_type(string)
Post type. Accepts 'post' or 'page' to name a few.
Default: 'post'

Code of set_post_type: wp-includes/post.php VER 4.9.8

<?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;
}

Related Functions

From tag: Custom post type (post_type)

More from category: Custom Types

No comments
    Hello, !     Log In . Register