Creating a custom endpoint for rest, I see the endpoint exists in the wp-json, but the request is returning 404

Question

I have attempted to register the route, tried all sorts of different parameters, feel my code looks like many of the examples on this site, but can’t figure out why it doesn’t work.

//Register REST Route
add_action('rest_api_init', 'add_advent_api');

function add_advent_api()
{
    register_rest_route('adventapi/v1', '/adventapi/', array(
        'methods' => 'WP_REST_Server::READABLE',
        'callback' => function () {
            return 'hello';
        },
        'args' => array(
            'adventyear' => array(
                'required' => true,
                'type' => 'integer',
                'description' => 'Year required',
                'minimum' => 1972,
                'maximum' => 9999,
            ),
            'adventday' => array(
                'required' => true,
                'type' => 'integer',
                'minimum' => 1,
                'maximum' => 24,
            ),
        ),
        'permission_callback' => function () {
            return true;
        }
    ));
}

function advent_query(WP_REST_Request $request)
{
    return 'i work';
    /*    $adventyear = $_GET['adventyear'];
    $adventday = $_GET['adventday'];

    $args = array(
        'post_type' => 'advent',
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'advent_year',
                'value' => $adventyear,
            ),
            array(
                'key' => 'advent_day',
                'value' => $adventday,
            ),

        ),

    );

    $query = new WP_Query($args);

    if ($query->have_posts()) {
        echo 'i ahve posts';
    } else {
        echo 'No Results';
    } */
}
0
Kyle Dunlop 2 months 0 Answers 16 views 0

Leave an answer