Код: Выделить всё
function wp_post_types() {
// Nicknames post type
register_post_type('subscription', array(
'supports' => array('title'),
'public' => true,
'show_ui' => true,
'labels' => array(
'name' => 'Subscription',
'add_new_item' => 'Add New Subscription',
'edit_item' => 'Edit Subscriptions',
'all_items' => 'All Subscriptions',
'singular_name' => 'Subscription'
),
'menu_icon' => 'dashicons-universal-access-alt'
));
}
add_action('init', 'wp_post_types');
Код: Выделить всё
add_action('rest_api_init', 'searchSubscription');
function searchSubscription() {
register_rest_route('CustomAPI/v3', 'search', array(
'methods' => WP_REST_SERVER::READABLE,
'callback' => 'getSubscription'
));
}
function getSubscription() {
$subscriptions = new WP_Query(array(
'perm' => 'readable',
'post_type' => 'subscription',
'posts_per_page' => '5'
));
$subscriptionResults = array();
while($subscriptions->have_posts()) {
$subscriptions->the_post();
array_push($subscriptionResults, array(
'title' => get_the_title(),
'region' => get_field('regi'),
'country' => get_field('country'),
'activity' => get_field('activity'),
'time' => get_field('time')
));
}
return $subscriptionResults;
}
Код: Выделить всё
{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}
Код: Выделить всё
[{"title":"Matt","region":"Central Visayas","country":"PH","activity":"2 months premium membership","time":"2018-01-31 06:36:53"},{"title":"Johnmark","region":"Central Visayas","country":"PH","activity":"Life time membership","time":"2018-01-31 06:29:52"}]
Подробнее здесь: https://stackoverflow.com/questions/486 ... d-in-users