wp_xmlrpc_server::get_custom_fields() WordPress Method

The wp_xmlrpc_server::get_custom_fields() method can be used to get a list of all the custom fields for a post. This is useful for getting information about a post that is not available in the standard fields.

wp_xmlrpc_server::get_custom_fields( int $post_id ) #

Retrieve custom fields for post.


Parameters

$post_id

(int)(Required)Post ID.


Top ↑

Return

(array) Custom fields, if exist.


Top ↑

Source

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

	public function get_custom_fields( $post_id ) {
		$post_id = (int) $post_id;

		$custom_fields = array();

		foreach ( (array) has_meta( $post_id ) as $meta ) {
			// Don't expose protected fields.
			if ( ! current_user_can( 'edit_post_meta', $post_id, $meta['meta_key'] ) ) {
				continue;
			}

			$custom_fields[] = array(
				'id'    => $meta['meta_id'],
				'key'   => $meta['meta_key'],
				'value' => $meta['meta_value'],
			);
		}

		return $custom_fields;
	}


Top ↑

Changelog

Changelog
VersionDescription
2.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