add_post_meta( 1, 'lionel____ticket', 'pia', true );
echo 'aaaaa1';
echo get_post_meta(1,'lionel____ticket',true);
echo 'aaaaa2';
Một ví dụ thực hiện trên app những bài viết đã xem :)
public function get_item( $request ) {
$post = $this->get_post( $request['id'] );
if ( is_wp_error( $post ) ) {
return $post;
}
$data = $this->prepare_item_for_response( $post, $request );
$response = rest_ensure_response( $data );
if ( is_post_type_viewable( get_post_type_object( $post->post_type ) ) ) {
$response->link_header( 'alternate', get_permalink( $post->ID ), array( 'type' => 'text/html' ) );
}
$wp_request_headers = array(
'Authorization' => 'Basic ' . base64_encode( 'wordpress:wordpress' )
);
$wp_request_url = 'http://app.yp.vn/wp-json/wp/v2/posts/'.$request['id'];
$wp_delete_post_response = wp_remote_request(
$wp_request_url,
array(
'method' => 'GET',
'headers' => $wp_request_headers
)
);
wp_remote_retrieve_response_code( $wp_delete_post_response );
wp_remote_retrieve_response_message( $wp_delete_post_response );
// ==========
if (is_user_logged_in()) {
$current_user_id = get_current_user_id();
$currentuseridpost = $current_user_id . '_' . $request['id'];
add_post_meta( $request['id'], $currentuseridpost, 1, true );
}
return $response;
}