0

我正在尝试使用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');

谁能指出语法错误是什么?

谢谢!

4

1 回答 1

1

我相信第 106 行是这个

  $count = $wpdb->get_var( \"SELECT COUNT(*) FROM $wpdb->posts $where\" );

因为有一个明显的语法错误。它应该是这样的:

$count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} $where" );
于 2012-01-18T05:46:14.723 回答