2012-01-18 55 views
0

我嘗試使用下面的函數從http://codex.wordpress.org/Function_Reference/count_user_postsPHP語法錯誤:從WordPress的法典WordPress的功能count_user_posts_by_type

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'); 

and

$authorcount = count_user_posts_by_type($author->ID, $post_type='videos'); 

任何人都可以指出語法錯誤是什麼?

謝謝!

回答

1

我相信線106是這樣的

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

因爲有一個明顯的語法錯誤。它應該是這樣的:

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