set_post_type

Definition:
function set_post_type( $post_id = 0, $post_type = 'post' ) {}

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

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.

Return values

returns:Amount of rows changed. Should be 1 for success and 0 for failure.

Source code

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) );



	if ( 'page' == $post_type )

		clean_page_cache($post_id);

	else

		clean_post_cache($post_id);



	return $return;

}

2847

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:

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

%d bloggers like this: