Custom Query for count_user_posts function

Your filter callback isn’t accepting any arguments from the hook. When you write the callback function you need to include the arguments passed in apply_filters, and in your add_filter() call you need to specify how many of the arguments you’re using:

// Accept all 4 arguments provided to callbacks for this filter.
function wpse_296863_author_post_count( $count, $userid, $post_type, $public_only ) {
    global $wpdb;
    $where = get_posts_by_author_sql( $post_type, true, $userid, $public_only );
    $where .= " AND post_date BETWEEN '2018-03-11' AND '2018-03-13'";
    $result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );

    return $result;
}
add_filter( 'get_usernumposts', 'wpse_296863_author_post_count', 10, 4 ); // Using 4 arguments.

Also note:

  • I prefixed the function. Your code should be prefixed with something unique to your project to avoid conflicts.
  • You were missing global $wpdb;. You can’t use $wpdb->get_var() without it.
  • I passed through the original values from the filter into get_posts_by_author_sql(), otherwise all post counts will be for the one user. I assume you’d done this for testing.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)