How to add author name to custom get_post_meta
-
Hi,
I’m a newbie in wordpress, finding it difficult to retrieve author name from custom get post meta api
Below is snippet of my code
add_action( 'rest_api_init', 'my_register_template_hook' ); function my_register_template_hook() { register_rest_field( 'post', // any post type registered with API 'appp', array( 'get_callback' => 'my_get_hook_data', 'update_callback' => null, 'schema' => null, ) ); }
function my_get_hook_data( $object, $field_name, $request ) { $data['post_detail']['below_title'] = '<span class="schedule-time">' . get_post_meta( $object['id'], 'author', true) . '</span>'; $data['post_detail']['above_title'] = '<div class="post-featured-wrap">' . get_the_post_thumbnail( $object['id'], 'large', array( 'class' => 'post-featured' ) ) . '</div>'; return $data; }
I could only retrieve featured image
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to add author name to custom get_post_meta’ is closed to new replies.