wp_xmlrpc_server::mt_getPostCategories() WordPress Method

The mt_getPostCategories() method is used to get a list of categories for a post in WordPress. This is useful for managing post categories via the XML-RPC interface.

wp_xmlrpc_server::mt_getPostCategories( array $args ) #

Retrieve post categories.


Parameters

$args

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

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


Top ↑

Return

(array|IXR_Error)


Top ↑

Source

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

6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
public function mt_getPostCategories( $args ) {
    $this->escape( $args );
 
    $post_ID  = (int) $args[0];
    $username = $args[1];
    $password = $args[2];
 
    $user = $this->login( $username, $password );
    if ( ! $user ) {
        return $this->error;
    }
 
    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.' ) );
    }
 
    /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    do_action( 'xmlrpc_call', 'mt.getPostCategories', $args, $this );
 
    $categories = array();
    $catids     = wp_get_post_categories( (int) $post_ID );
    // First listed category will be the primary category.
    $isPrimary = true;
    foreach ( $catids as $catid ) {
        $categories[] = array(
            'categoryName' => get_cat_name( $catid ),
            'categoryId'   => (string) $catid,
            'isPrimary'    => $isPrimary,
        );
        $isPrimary    = false;
    }
 
    return $categories;
}


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