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?
- Fatal error: Call to undefined function mysql_connect()
- the_date() not working
- How to return number of found rows from SELECT query
- How to loop through JSON data in wordpress WP REST API
- How to make WordPress plugin check for database changes and then do something?
- How to make an meta_query optional?
- wordpress custom endpoint multiple params
- Display Post co-authored in Author Page
- PHP/MySQL issues when running WP on EC2 cloud [closed]
- WordPress get pagination on wpdb get_results
- Sorting Posts | Alphabetical Order
- How do I fetch all comments per post via WP REST API?
- PHP code inside shortcodes
- Show MySQL errors that occur when I excute $wpdb->insert()
- Is XAMPP faster than running LAMP in WSL on Windows 10? [closed]
- Get updated query results on page after insert in database
- WordPress not reflecting changed of the database
- How can I fix WordPress installation errors?
- WordPress, AJAX and pre_get_posts using conditional tags
- How to split links generated into an xml sitemap to avoid exceeding 30 sec maximum execution time?
- Hacked WordPress website /Homepage redirect [closed]
- Exclude posts based on meta value
- Database query works fine outside WordPress
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- Large Woocommerce Site (83,000 items), What Can I Do? [closed]
- Help with a $wpdb MySQL Query
- Can’t Query Custom Table Using $wpdb Method
- $wpdb returns duplicate posts
- Update postmeta after theme switch
- How to use mysql LIKE with wpdb?
- Get all posts as an array ID => Name
- Passing an array into WP_Query as a variable
- Custom query vars filters problem with pagination
- Do not duplicate posts with multiple categories in multiple loops
- How to use AJAX in WordPress in MYSQL query?
- Use variable in SQL statement
- Processing ajax call to php to insert into mysql database
- Displaying Event within two given time frames
- Remove Post if Advanced Custom Field is checked to fix paging
- WordPress Custom Query: Combining Two Functions
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- WP_Query: How to get results from both meta_key options?
- Output product category link from WP_Query
- Database SQL query error
- Load more posts using AJAX based on posts inside WP_Query
- How to select post ID for given parent name with nested prepared queries?
- posts_per_page displays only 2 posts instead of 4 posts
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- How to optimize and reduce excessive database queries
- Store GA Client ID in User DB
- Need to show 7 posts from actual date
- Add code to the header of posts by particular author
- Paged WP_Query is quitting on page 3
- PHP 7.2.18 | Your PHP installation appears to be missing the MySQL extension which is required by WordPress
- Need help with format of nested array in MySQL
- Meta query not showing result properly
- Help on Wp_query to print an term
- Inserting other fields to existing registration form in a WordPress theme
- making a search.php query
- Splitting table data to pages with numbers
- Site doesnt work once PHP changed to 7.1
- How to detect if a revision was made by woocommerce or wordpress?
- Efficient way of querying for a “fallback” post?
- WordPress WPDB::insert 13th param is always blank (only if format)
- Ajax not updating to database
- can’t delete a row from post_meta table
- Create a hierarchical loop at predefined markup requirements
- MySQL query in WordPress with AJAX
- retrieve wordpress post-meta using php not wordpress functions
- Splash pages on a high traffic site
- Query seems to be duplicated
- Pagination in category.php not functioning
- How to sort custom sortable column by custom table value
- running an existing WordPress site from Visual Studio Code?