$wpdb->get_results()
returns an array of rows from the queried table and not a mysqli_result object, so you can just use foreach
like so:
$result = $wpdb->get_results( $sql );
foreach ( $result as $row ) {
echo $row->correct_count;
// ...
}
And by default, each row is an object with the columns (<column name> => <column value>
) in the database table, but if you want the item be an associative array, then pass ARRAY_A
as the second parameter for $wpdb->get_results()
.
$result = $wpdb->get_results( $sql, ARRAY_A );
foreach ( $result as $row ) {
echo $row['correct_count'];
// ...
}
Please refer to the reference for further information.
Related Posts:
- Delete post revisions on post publish
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Successful or Error Message after running mysql code in functions.php
- Insert all post IDs in new database table
- PHP code inside shortcodes
- WSoD being caused by this piece of code
- How to check if a meta value has already been assigned to any user?
- $wpdb->wp_users returning empty value for
- Multiple meta_key in one global $wpdb;
- How to use mysql LIKE with wpdb?
- making php value numeric
- SQL error with custom query
- Modify WooCommerce used to get all orders in dashboard
- How can I display a query in a page?
- How to set up an auto delete post?
- How to remove or change the “W” icon in “My Sites”?
- get a simple array of all of the term names that exist in all taxonomies
- Login/logout in header
- How to display posts by current user in a drop down
- Logged in user ID as post ID
- mysql query from wordpress page using custom table
- How does WordPress insert Paragraphs in posts
- WordPress Access allowed to fewer pages till user logs in
- Linking text within textarea of custom meta box
- User management system similar to wordpress one?
- Importing Geo data into wordpress database
- Show css depending on activity type in BuddyPress activity-loop [closed]
- only show container with next/prev links if they exist?
- How to combine wordpress_logged_in cookies in one cookie?
- Populate dropdown with Child Pages based on Parent Page chosen
- How can I remove a function that has been added to wordpress with add_filter?
- Change the WP Video Shortcode Output
- Show categories then when clicked on a category list all sub category and when clicked show all posts in that sub category
- remove wp floating submenu in wp dashboard
- How to put “Read more” link in Custom Excerpt inside p tag?
- How can I fix WordPress installation errors?
- Two Different Links for Same Product – WooCommerce [closed]
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- ACF: how do I get the fields and its values of a specific group?
- How to store data from multiple forms using ajax and php
- How to control WordPress image metadata (using Imagick)?
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Get value from shortcode to do something
- SQL Injection blocked by firewall
- PHP 8, AJAX mail form to function.php doesn’t work
- How do I add custom bulk actions to multiple custom post types?
- Error when adding excerpt to the content through functions.php
- Automatically adding new post categories to menu
- Add data attribute to each li in menu
- Get post id in a function when edit/add a post
- Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
- How to complete two other input fields, completed the first
- Prev/Next child navigation for current page modifications?
- Adding rel tag to all external links
- How to display data from custom table in wordpress phpmyadmin
- Calculating a large number of MYSQL queries as customshort codes, slow
- How can I apply_filters from inside a function?
- function to assign user role based on a field from usermeta
- what is the best practice to add new field to an api route
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Use DOMDocument with ob_start breaks my HTML code
- Auto-update products after they were published – Woocommerce
- How to prevent WP_Query function from returning all posts when empty?
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- JS file work only in index page
- Display a specific category of products in shop page and disable code for specific actions
- Woocommerce related product text
- esc_html_e() is not translating string in wordpress [closed]
- Removing “wpautop” (auto tags) only on certain pages?
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Fatal error: Uncaught Error: Call to undefined function test()
- How to pick the default selected value in wordpress dropdown?
- 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
- Validate functions before inserting then into functions.php
- How to retrieve current wordpress profile page URL?
- Firing schema via code in functions.php doesn’t work
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- Get page that displays all children of taxonomy parent
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- get author_name from queried post
- How can I save unique user data on my site? [closed]
- Why ajax doesn’t work on certain wordpress hooks?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- How to call plugin function per site in a multisite?
- Print last modified date only on posts
- different id for same element visual composer [closed]
- WooCommerce: How can I get orders with a custom ID in order meta data object?
- Tax query in pre_get_posts not working
- Update results, Before deleting the related category [closed]
- WordPress Gravatar filter is removing my custom attributes
- foreach loop still echoes array
- trigger html cleanup for all posts
- Error in custom php function doesn’t exist
- dynamic dependent select dropdown
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Sum the total amount of a specific product purchased per user and display in table
- Ordering users by custom user meta
- Custom shortcode outputs plain text instead of HTML at top of post