- $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
- dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
+ $condition = ["`term` = ? AND `otype` = ? AND `type` = ? AND `uid` = ?",
+ $file, TERM_OBJ_POST, TERM_FILE, local_user()];
+ $params = ['order' => ['tid' => true], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
+ $result = dba::select('term', ['oid'], $condition);
+
+ $posts = [];
+ while ($term = dba::fetch($result)) {
+ $posts[] = $term['oid'];
+ }
+ dba::close($terms);
+
+ $condition = ['uid' => local_user(), 'id' => $posts];