Opened 7 years ago
Last modified 7 years ago
#44752 reviewing defect (bug)
wp_get_archives() with the parameter limit = 0 generates an error
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | 1.2 |
| Component: | Posts, Post Types | Keywords: | has-patch |
| Focuses: | Cc: |
Description
Hello.
I'm working on an extension of the WP_Widget_Archives class, in which I implement the ability to specify the archive type and the limit of output links. These parameters are then passed to the wp_get_archives() function.
It is noticed that if the parameter limit=0, then the query to the database turns out to be wrong and the following error is generated:
[You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0' at line 1] SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date) ORDER BY post_date DESC 0
Of course, I can check this parameter from my side and zero is replaced by an empty string, but it is logical that the function itself does this.
Attachments (3)
Change History (13)
#3
@
7 years ago
@earnjam thanks for the response. If limit=0, the !empty() construct does not work, so $limit=0. Then this zero is substituted into the sql query.
#4
@
7 years ago
Ah good catch. The essentially triple negative of ! empty( 0 ) is tough to follow.
I also didn't initially notice that down below that we pass on the value of $r['limit'] to the query no matter what, which is why it still got through.
Duplicate of #27834 which looks like it was fixed in [28560]. Not sure why you'd be getting that at this point.
Even if it got through the
! empty()check somehow, at the very least it should have the wordLIMITin the query:https://github.com/WordPress/WordPress/blob/master/wp-includes/general-template.php#L1757