Skip to content

Commit 96167a5

Browse files
committed
add fields limit option to posts
1 parent 62fa89d commit 96167a5

1 file changed

Lines changed: 32 additions & 27 deletions

File tree

lib/requests/params_post_list.dart

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ParamsPostList {
2626
final List<int> excludeTags;
2727
final bool? sticky;
2828

29+
/// Which fields to retrieve. If empty, gets all fields.
30+
final List<String> fields;
31+
2932
ParamsPostList({
3033
this.context = WordPressContext.view,
3134
this.pageNum = 1,
@@ -47,6 +50,7 @@ class ParamsPostList {
4750
this.includeTags = const [],
4851
this.excludeTags = const [],
4952
this.sticky,
53+
this.fields = const []
5054
});
5155

5256
Map<String, String> toMap() {
@@ -71,36 +75,37 @@ class ParamsPostList {
7175
'tags': '${listToUrlString(includeTags)}',
7276
'tags_exclude': '${listToUrlString(excludeTags)}',
7377
'sticky': '${this.sticky == null ? '' : this.sticky}',
78+
'_fields': this.fields.join(','),
7479
};
7580
}
7681

77-
ParamsPostList copyWith({
78-
int? pageNum,
79-
int? perPage,
80-
}) {
81-
return ParamsPostList(
82-
afterDate: afterDate,
83-
beforeDate: beforeDate,
84-
context: context,
85-
excludeAuthorIDs: excludeAuthorIDs,
86-
excludeCategories: excludeCategories,
87-
excludePostIDs: excludePostIDs,
88-
excludeTags: excludeTags,
89-
includeAuthorIDs: includeAuthorIDs,
90-
includeCategories: includeCategories,
91-
includePostIDs: includePostIDs,
92-
includeTags: includeTags,
93-
offset: offset,
94-
order: order,
95-
orderBy: orderBy,
96-
pageNum: pageNum ?? this.pageNum,
97-
perPage: perPage ?? this.perPage,
98-
postStatus: postStatus,
99-
searchQuery: searchQuery,
100-
slug: slug,
101-
sticky: sticky
102-
);
103-
}
82+
ParamsPostList copyWith({
83+
int? pageNum,
84+
int? perPage,
85+
}) {
86+
return ParamsPostList(
87+
afterDate: afterDate,
88+
beforeDate: beforeDate,
89+
context: context,
90+
excludeAuthorIDs: excludeAuthorIDs,
91+
excludeCategories: excludeCategories,
92+
excludePostIDs: excludePostIDs,
93+
excludeTags: excludeTags,
94+
includeAuthorIDs: includeAuthorIDs,
95+
includeCategories: includeCategories,
96+
includePostIDs: includePostIDs,
97+
includeTags: includeTags,
98+
offset: offset,
99+
order: order,
100+
orderBy: orderBy,
101+
pageNum: pageNum ?? this.pageNum,
102+
perPage: perPage ?? this.perPage,
103+
postStatus: postStatus,
104+
searchQuery: searchQuery,
105+
slug: slug,
106+
sticky: sticky,
107+
fields: fields);
108+
}
104109

105110
@override
106111
String toString() {

0 commit comments

Comments
 (0)