wp php get rows number from mysql

Use the following code to get the number of rows from a MySQL database in WordPress using the wpdb class:

global $wpdb; $result = $wpdb->get_results( "SELECT COUNT() FROM your_table_name" ); $count = (int) $result[0]->COUNT();

Explanation: 1. Declare the global $wpdb variable to access the WordPress database. 2. Use the $wpdb->get_results function to execute the SQL query "SELECT COUNT() FROM your_table_name" and store the result in the $result variable. 3. Retrieve the count from the $result object by accessing the first element and casting it to an integer using (int) $result[0]->COUNT().