Skip to content

Commit

Permalink
Add more condition on SQL to prevent unexpected result.
Browse files Browse the repository at this point in the history
  • Loading branch information
ve3 committed Dec 11, 2024
1 parent 866981b commit 46fca21
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions App/Models/PostOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public function resetAllPostsOrder($updateOnlyMenuOrderZero = false)
$stickies = get_option('sticky_posts');
if (!empty($stickies)) {
$stickiesPlaceholders = array_fill(0, count($stickies), '%d');
$sql = 'SELECT `ID`, `menu_order` FROM `' . $wpdb->posts . '` WHERE `ID` IN (' . implode(', ', $stickiesPlaceholders) . ')';
$sql = 'SELECT `ID`, `menu_order` FROM `' . $wpdb->posts . '` WHERE ';
$sql .= ' `post_type` = %s';
$sql .= ' AND `ID` IN (' . implode(', ', $stickiesPlaceholders) . ')';
$sql .= ' AND `post_status` IN(\'' . implode('\', \'', $this->allowed_order_post_status) . '\')';
$sql .= ' ORDER BY `post_date` DESC';
$prepared = $wpdb->prepare($sql, $stickies);
$prepared = $wpdb->prepare($sql, array_merge([\RdPostOrder\App\Models\PostOrder::POST_TYPE], $stickies));
$stickyPosts = $wpdb->get_results($prepared);
unset($prepared, $sql);
}
Expand Down

0 comments on commit 46fca21

Please sign in to comment.