我正在尝试使用http://codex.wordpress.org/Function_Reference/count_user_posts
function count_user_posts_by_type($userid, $post_type='post') {
global $wpdb;
$where = get_posts_by_author_sql($post_type, TRUE, $userid);
$count = $wpdb->get_var( '"SELECT COUNT(*) FROM $wpdb->posts $where'" );
return apply_filters('get_usernumposts', $count, $userid);
}
但我得到以下错误:
Parse error: syntax error, unexpected '"', expecting T_STRING in .../wp-content/themes/aa/functions.php on line 106
在我的模板中,我尝试了两种方式:
$authorcount = count_user_posts_by_type($author->ID, 'videos');
和
$authorcount = count_user_posts_by_type($author->ID, $post_type='videos');
有人能指出语法错误是什么吗?
谢谢!
我相信第106行就是这个
$count = $wpdb->get_var( '"SELECT COUNT(*) FROM $wpdb->posts $where'" );
因为有一个明显的语法错误。应该是这样的:
$count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} $where" );