wp_xmlrpc_server::mt_setPostCategories() WordPress Method

The mt_setPostCategories() method is used to set the categories for a post in WordPress. This is done by setting the post's MtCategories element to an array of category names.

wp_xmlrpc_server::mt_setPostCategories( array $args ) #

Sets categories for a post.


Parameters

$args

(array)(Required)Method arguments. Note: arguments must be ordered as documented.

  • 'post_ID'
    (int)
  • 'username'
    (string)
  • 'password'
    (string)
  • 'categories'
    (array)


Top ↑

Return

(true|IXR_Error) True on success.


Top ↑

Source

File: wp-includes/class-wp-xmlrpc-server.php

	public function mt_setPostCategories( $args ) {
		$this->escape( $args );

		$post_ID    = (int) $args[0];
		$username   = $args[1];
		$password   = $args[2];
		$categories = $args[3];

		$user = $this->login( $username, $password );
		if ( ! $user ) {
			return $this->error;
		}

		/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
		do_action( 'xmlrpc_call', 'mt.setPostCategories', $args, $this );

		if ( ! get_post( $post_ID ) ) {
			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
		}

		if ( ! current_user_can( 'edit_post', $post_ID ) ) {
			return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
		}

		$catids = array();
		foreach ( $categories as $cat ) {
			$catids[] = $cat['categoryId'];
		}

		wp_set_post_categories( $post_ID, $catids );

		return true;
	}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More