Uses
Uses | Description |
---|---|
wp-admin/includes/post.php: has_meta() | Get meta data for the given post ID. |
wp-includes/capabilities.php: current_user_can() | Returns whether the current user has the specified capability. |
Retrieve custom fields for post.
(int) (Required) Post ID.
(array) Custom fields, if exist.
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; }
Version | Description |
---|---|
2.5.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/get_custom_fields