一聚教程网:一个值得你收藏的教程网站

热门教程

解决wordpress自带admin-ajax文件请求ajax太慢的问题

时间:2022-06-25 19:04:23 编辑:袖梨 来源:一聚教程网

优化代码

 代码如下 复制代码

// Force a short-init since we just need core WP, not the entire framework stack
define( 'SHORTINIT', true );
 
// Build the wp-load.php path from a plugin/theme
$wp_root_path = dirname( dirname( dirname( __FILE__ ) ) );
// Require the wp-load.php file (which loads wp-config.php and bootstraps WordPress)
require( $wp_root_path . '/wp-load.php' );
 
// Include the now instantiated global $wpdb Class for use
global $wpdb;
 
// Do your PHP code for rapid AJAX calls with WP!
 
// Example: Retrieve and display the number of users.
$user_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->users;" ) );
echo "

User count is {$user_count}

";

热门栏目