如何将WordPress查询转换为PDO查询

时间:2021-12-05 作者:flexi2202

如何将这个在wordpress下工作的查询转换为在php中的另一个站点上使用

  global $wpdb;
        $ID_CATEGORY = 10; 
        $query = $wpdb->prepare("SELECT {$wpdb->prefix}users.ID, {$wpdb->prefix}users.display_name as user_nicename, COUNT(*) as count 
        FROM {$wpdb->prefix}posts, {$wpdb->prefix}users, {$wpdb->prefix}term_relationships 
        WHERE {$wpdb->prefix}posts.post_type=\'post\' 
        AND {$wpdb->prefix}posts.post_status=\'publish\' 
        AND {$wpdb->prefix}posts.post_author = {$wpdb->prefix}users.ID 
        AND {$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id 
        AND {$wpdb->prefix}term_relationships.term_taxonomy_id = %d
        GROUP BY post_author ORDER BY count DESC LIMIT 5 ;", $ID_CATEGORY);
        $results = $wpdb->get_results($query, OBJECT);

1 个回复
SO网友:flexi2202

我刚找到答案

"SELECT post_title ,post_date, display_name ,wp_users.ID, wp_users.display_name as user_nicename, COUNT(*) as count 
        FROM wp_posts, wp_users, wp_term_relationships 
        WHERE wp_posts.post_type=\'post\' 
        AND wp_posts.post_status=\'publish\' 
        AND wp_posts.post_author = wp_users.ID 
        AND wp_posts.ID = wp_term_relationships.object_id 
        AND wp_term_relationships.term_taxonomy_id = \'10\'
        GROUP BY post_author ORDER BY count DESC LIMIT 5 ;"

相关推荐

在该主题的函数.php文件中添加html链接

我使用的选项是,人们需要有一个帐户才能结账。因此,签出页面被阻止。此时,您将收到消息“您必须登录才能结账”。为了提高客户不必搜索单击下一步的位置,我想添加额外的超链接文本。我发现这段代码工作得很好,但HTML在“我的消息”区域中不起作用。function filter_woocommerce_checkout_must_be_logged_in_message( $message ) { $message = \'MY MESSAGE\'; return $message;