There are 3 issues with your code:
-
The proper syntax of registering your custom REST API route, is as follows:
register_rest_route( $namespace, $base_URL, $args, $override );
So:
register_rest_route( 'boss/v1', '/latest-quiz-results', array( 'methods' => 'GET', 'callback' => 'get_latest_quiz_results' ) );
Consult the reference for more information.
-
In the
get_latest_quiz_results()
,$wpdb
is not defined because you’re missingglobal $wpdb;
at the top:function get_latest_quiz_results() { global $wpdb; // Add this. ... return $results; }
-
Also in
get_latest_quiz_results()
, you incorrectly calledwpdb::prepare()
— the second parameter is mandatory, and there needs to be at least one placeholder (e.g.%s
). So for example:$query = $wpdb->prepare( "SELECT ... WHERE 5PxenC_learndash_user_activity_meta.activity_meta_key = %s", 'pass' );
Related Posts:
- Show only one post for each author ( Page loads too slow )
- Modern Tribe Calendar wp-query with meta query not working at all
- if statement on database query
- Continue execution after WP REST API response
- Looking for most performant way to execute several similar WP queries within shortcodes
- How to filter posts by post format “standard” from wp-json api?
- Why is variable not working on custom sql query using wpdb?
- WordPress custom slug (endpoint) and compare all links
- How to securely provide a $_POST var in WP_Query with PHP 7?
- Create WP_Query to search for posts by their categories or their parent/child categories
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- inserting a post from an extern php file but post content doesn’t show on wp site
- Hide posts if user is added to it WP_query
- WordPress WP_Query without query GET parameters
- How to WP_Query posts order by parent title?
- WP_REST_Response – How to return Gzip answer and add Content-encoding header?
- Passing in MySQL prepare statement parameter separately throwing error
- Usermeta data unserialize, extract and display in table in WordPress
- how to get data from two different table from wordpress database
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- Query doesn’t display text data with apostrophes
- SQL Query Search page
- How can I display a query in a page?
- Custom query_posts() parameter
- Execute multiple PHP Snippets causes error?
- What is different about using admin-ajax.php in an endpoint and just submitting a form from the front end?
- REST API Plugin Update call back not updating the plugin
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- Can’t search posts using WP_QUERY inside AJAX Function
- Show MySQL errors that occur when I excute $wpdb->insert()
- How to query for pages/post depending on slug?
- How can I use wp_query to show all product data using just the products ID?
- Why is the post meta[] empty when I make a call to the wordpress rest api?
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Get WooCommerce product details and transfer them to a custom DB table
- Random order of WP_Query results with highest meta value
- WordPress 5 WP REST routes – No errors
- Custom page archive query by url var calling page twice on one of my custom queries?
- Is XAMPP faster than running LAMP in WSL on Windows 10? [closed]
- Remove one value in dismissed_wp_pointers?
- Is there an equivalent to WP_Error object I can return in the case of a successful REST request?
- WordPress Site Running Extremely Slow on Dedicated Server
- Checking for new message using AJAX and PHP. Server overload?
- How can I export posts with featured images, without download them
- How to query for posts with a null or blank post_name?
- WordPress pagination not working with search page
- get current custom post ID by WP_Query method
- Using foreach loop breaks
- Can’t get wp_insert_post to work
- Accessing data from a non-WP database/table within a page content
- WP Query with custom Shortcode
- What is a valid parent for get_terms()?
- wp_query with cat not working
- Get updated query results on page after insert in database
- WSoD being caused by this piece of code
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- How to use an associative array in post__in with WP_Query?
- I want to select the from values from database in WordPress? [closed]
- WordPress not reflecting changed of the database
- If Query In Sidebar
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- mysql query from wordpress page using custom table
- Compare post-IDs within WP_Query? (Less than / Greater than)
- User management system similar to wordpress one?
- Importing Geo data into wordpress database
- How can I fix WordPress installation errors?
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- SQL Injection blocked by firewall
- How to use $query->set with post__in?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- How to check if a meta value has already been assigned to any user?
- How to display data from custom table in wordpress phpmyadmin
- Calculating a large number of MYSQL queries as customshort codes, slow
- Woocommerce hook run after an Order been created through REST API
- what is the best practice to add new field to an api route
- Loading the same WP_Query in two different wordpress .php templates
- How to prevent WP_Query function from returning all posts when empty?
- How to show single category archive
- Dynamic content based on a URL parameter
- Display a specific category of products in shop page and disable code for specific actions
- Woocommerce api: create product with images – bad request
- Using WP-API and SSE not authenticating user ID
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- How can I save unique user data on my site? [closed]
- Add more button if more 8 items
- How to store post ID’s in cookie or session to display the same posts later
- Update results, Before deleting the related category [closed]
- Sum the total amount of a specific product purchased per user and display in table
- Ordering users by custom user meta
- WordPress, AJAX and pre_get_posts using conditional tags
- Are nonces in WP REST API optional by default?
- Get users that likes the post
- Long running queries
- How to split links generated into an xml sitemap to avoid exceeding 30 sec maximum execution time?
- Hacked WordPress website /Homepage redirect [closed]
- Replacing mysql_escape_string in a custom plugin when moving to PHP7
- Exclude posts based on meta value
- how to save selected option in variable for rest api category filter
- Weird 404 URL Problem – domain name being placed at end of urls