flutter_wordpress
flutter_wordpress copied to clipboard
Post Author Invalid
I just followed the tutorial, using my own WordPress site url. But some of the post author is invalid. The author name that appears instead is another author on my site
I'm finding similar behavior. Posts show with an incorrect author. The most recent post appears to be correct, not sure if it's merely by chance or what, but the rest of them are incorrect.
Edit: I think I see why this is happening.
In your fetchUser method, which is called by the _postBuilder method in the fetchPosts method, you are using the search api endpoint and it is often finding multiple users (if I search for id# 7, I find user with the id=7 and myself, which has a 7 in the username) but only returning the first result, which is often the incorrect result. A better method would be to query the users endpoint (/wp/v2/users/
String endpoint = '';
if (id != null) {
endpoint = '/$id'; //params['search'] = '$id';
} else if (email != null)
params['search'] = email;
else if (username != null) params['search'] = username;
endpoint += constructUrlParams(params);
url.write(endpoint);
final response = await http.get(url.toString(), headers: _urlHeader);
if (response.statusCode >= 200 && response.statusCode < 300) {
final jsonStr = json.decode(response.body);
if (jsonStr.length == 0)
throw new WordPressError(
code: 'wp_empty_list', message: "No users found");
return User.fromJson(jsonStr is List ? jsonStr[0] : jsonStr);