wp_xmlrpc_server::get_custom_fields()publicWP 2.5.0

Retrieves custom fields for post.

Method of the class: wp_xmlrpc_server{}

No Hooks.

Return

Array. Custom fields, if exist.

Usage

$wp_xmlrpc_server = new wp_xmlrpc_server();
$wp_xmlrpc_server->get_custom_fields( $post_id );
$post_id(int) (required)
Post ID.

Changelog

Since 2.5.0 Introduced.

wp_xmlrpc_server::get_custom_fields() code WP 6.5.2

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