You say “However, I know this is not a good way to do this” in your self answer. One thing I could add answering your question and using your answer is, you can use SQL_CALC_FOUND_ROWS with $wpdb
$result = $wpdb->get_results(
"SELECT SQL_CALC_FOUND_ROWS * FROM `wp_table` WHERE 1 LIMIT 10;"
);
$total_count = $wpdb->get_var(
"SELECT FOUND_ROWS();"
);
This way you don’t have to run the query twice.
Related Posts:
- How to return number of found rows from SELECT query
- Can i use php sql functions instead of $wpdb?
- $wpdb->delete column values IN ARRAY()?
- How to implement WP_List_Table? WP_List_Table giving array instead of a value in listing table
- Custom query to get post names beginning with a digit
- Ajax $wpdb not returning table data
- Converting MYSQL to WordPress $WPDB
- Why is variable not working on custom sql query using wpdb?
- Show MySQL errors that occur when I excute $wpdb->insert()
- Can’t get wp_insert_post to work
- WSoD being caused by this piece of code
- I want to select the from values from database in WordPress? [closed]
- Update results, Before deleting the related category [closed]
- wp query foreach deleting record returning only first or last item
- Database query works fine outside WordPress
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- $wpdb->insert() does not Insert record in a table
- Help with a $wpdb MySQL Query
- Custom array from a query only write the last row of the query
- $wpdb returns duplicate posts
- Mixing variables into an array when inserting values
- Use $wpdb or other PHP script method to find/replace in WP database
- How can I add a new row in a separate database when someone registers via WordPress?
- Basic wpdb update question
- I can’t update my data through $wpdb
- Output: “Array”
- How to use mysql LIKE with wpdb?
- How do I prepare strings for insertions as values into a MySQL table?
- How to use AJAX in WordPress in MYSQL query?
- form $_post action value gets truncated after it passes through two forms
- Why won’t this wpdb get_results query return results?
- WPDB secure custom form
- Add row to custom database Table and delete all rows older than 1 day
- select a single val though a table in wordpress
- populate select options from extra mysql table data
- Query the links Database
- MySQL Query Returns Array () In Shortcode
- Passing in MySQL prepare statement parameter separately throwing error
- Convert a column of a table containing an Array as response in HTML
- Database SQL query error
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- Conditional formatting on data fetched from MYSQL
- What is the correct way to search 3 custom fields only in WordPress?
- Using wpdb to connect to a different database is not working
- Rewrite SQL query as a prepared statement and use in foreach loop
- Advanced WordPress SQL Query
- MySQL query in WordPress with AJAX
- Passed variable gets undefined variable error on insert on next page
- MySQL queries in WordPress
- Using the same shortcode to show any table from the database
- MySQL database migration to WordPress
- Error resetting database index using ALTER TABLE in $wpdb->query
- Putting form result in my database
- How can I update a value of a field depending on outside source?
- How to properly prepare a column name if passed to a stored procedure?
- How can I save unique user data on my site? [closed]
- Sum the total amount of a specific product purchased per user and display in table
- Ordering users by custom user meta
- Long running queries
- How WordPress reacts to a lack of memory of the server [closed]
- wpdb php get_var query to get ID for URL image doesn’t work for ID over 999
- How to split links generated into an xml sitemap to avoid exceeding 30 sec maximum execution time?
- Hacked WordPress website /Homepage redirect [closed]
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- Replacing mysql_escape_string in a custom plugin when moving to PHP7
- Weird 404 URL Problem – domain name being placed at end of urls
- Refresh table data with Ajax
- Search not showing all results
- database sent to a JSON file
- inserting a post from an extern php file but post content doesn’t show on wp site
- Pagination in plugin’s backend
- $wpdb->wp_users returning empty value for
- Large Woocommerce Site (83,000 items), What Can I Do? [closed]
- Using custom tables for old posts
- PHP code to use on next & previouspage links
- Pagination for custom shop loop woocommerce
- WordPress SQL injection
- Not connecting to database in file with multiple MySQL connections
- Way to bulk make all my tags lowercase?
- $Wpdb post meta query is not working with mutliple meta keys and values? [closed]
- How i can obtain all the post meta for a specific post as an array?
- Fatal error: Call to a member function query() on a non-object
- multiple where condition in result query
- pagination on data fetched using SQL query
- How to get all author posts outside of author templates
- Grouping posts by a custom meta value
- Multiple meta_key in one global $wpdb;
- How to create pagination for users list using custom array?
- WordPress member notification
- Can’t Query Custom Table Using $wpdb Method
- Moving wordpress site from localhost to live server using GoDaddy cPanel
- How does WP work in conjunction with a web server?
- Custom Pagination is Broken
- Error using WordPress $wpdb object to get result from custom table
- WordPress Block developer from exporting Database via PHP
- How to retrieve the data from the sever and displaying it in a page?
- Querying Database with wpdb
- Pagination on Custom Post
- Next post link on a bootstrap button
- Can’t update multiple rows with $wpdb query