• Resolved programmin

    (@programmin)


    In a previous version, ajax call to /wp-json/wp-statistics/v2/metabox?ago=7&no-data=no&name=hits&_=…number

    was working and returning data. On the latest WP-statistics this is now returning

    {“code”:”not_found_meta_box”,”message”:”Invalid MetaBox Name in Request.”}

    Only change is wp-statistics, version latest (from version 14.9 previously).

Viewing 1 replies (of 1 total)
  • Mehmet

    (@gandomi)

    Dear @programmin,

    Thank you for opening the thread!

    The error you’re seeing ({“code”:”not_found_meta_box”,”message”:”Invalid MetaBox Name in Request.”}) is occurring because the MetaBox functionality has been deprecated in version 14.12 of WP Statistics.

    Recommended Solution:

    Use the new methods provided by WP Statistics to retrieve hits data:

    // Using the Hits class directly
    $hits = WP_STATISTICS\Hits::record();

    If you need to maintain the same API endpoint structure, you can create a custom endpoint in your theme’s functions.php:

    add_action('rest_api_init', function () {
    register_rest_route('wp-statistics/v2', '/metabox', array(
    'methods' => 'GET',
    'callback' => 'custom_metabox_callback',
    'permission_callback' => function () {
    return current_user_can('manage_options');
    }
    ));
    });

    function custom_metabox_callback($request) {
    $name = $request->get_param('name');
    if ($name === 'hits') {
    $hits = WP_STATISTICS\Hits::record();
    return rest_ensure_response($hits);
    }
    return new WP_REST_Response(array('code' => 'not_found_meta_box', 'message' => 'Invalid MetaBox Name in Request.'), 400);
    }

    Let us know if you need any further assistance!

    Regards,
    Mehmet

    • This reply was modified 1 year ago by Mehmet.
Viewing 1 replies (of 1 total)

The topic ‘REST API not returning back data to admin.’ is closed to new replies.