Skip to content

Commit 7f6c182

Browse files
committed
Merge pull request wordpress-mobile#3890 from wordpress-mobile/issues/3889-fix-pages-predicate
Fixes the structure of the page lists fetch predicate.
2 parents 98c2bdb + ac5d6cc commit 7f6c182

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

WordPress/Classes/ViewRelated/Pages/PageListViewController.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,23 @@ - (NSPredicate *)predicateForFetchRequest
199199
NSPredicate *basePredicate = [NSPredicate predicateWithFormat:@"blog = %@ && original = nil", self.blog];
200200
[predicates addObject:basePredicate];
201201

202+
NSString *searchText = [self currentSearchTerm];
202203
NSPredicate *filterPredicate = [self currentPostListFilter].predicateForFetchRequest;
204+
205+
// If we have recently trashed posts, create an OR predicate to find posts matching the filter,
206+
// or posts that were recently deleted.
207+
if ([searchText length] == 0 && [self.recentlyTrashedPostIDs count] > 0) {
208+
NSPredicate *trashedPredicate = [NSPredicate predicateWithFormat:@"postID IN %@", self.recentlyTrashedPostIDs];
209+
filterPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[filterPredicate, trashedPredicate]];
210+
}
203211
[predicates addObject:filterPredicate];
204212

205-
NSString *searchText = self.searchController.searchBar.text;
206213
if ([searchText length] > 0) {
207214
NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"postTitle CONTAINS[cd] %@", searchText];
208215
[predicates addObject:searchPredicate];
209216
}
210217

211218
NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];
212-
if ([searchText length] == 0 && [self.recentlyTrashedPostIDs count] > 0) {
213-
NSPredicate *trashedPredicate = [NSPredicate predicateWithFormat:@"postID IN %@", self.recentlyTrashedPostIDs];
214-
predicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[predicate, trashedPredicate]];
215-
}
216219

217220
return predicate;
218221
}

0 commit comments

Comments
 (0)