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 

私のテンプレートでは、2つの方法で使用してみました。

$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 に答える