WordPress.org

Make WordPress Core

Opened 15 months ago

Last modified 10 months ago

#44752 reviewing defect (bug)

wp_get_archives() with the parameter limit = 0 generates an error

Reported by: campusboy1987 Owned by: SergeyBiryukov
Milestone: Future Release Priority: normal
Severity: normal Version: 1.2
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:
PR Number:

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)

wp_get_archives.patch (538 bytes) - added by campusboy1987 15 months ago.
44752.diff (614 bytes) - added by campusboy1987 15 months ago.
With the previous version, I hurried, sorry. That's more correct in my opinion.
44752-2.diff (605 bytes) - added by campusboy1987 15 months ago.
the condition is corrected

Download all attachments as: .zip

Change History (13)

#1 @earnjam
15 months ago

  • Version changed from 4.9.8 to 1.2

#2 @earnjam
15 months ago

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 word LIMIT in the query:
https://github.com/WordPress/WordPress/blob/master/wp-includes/general-template.php#L1757

#3 @campusboy1987
15 months 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.

@campusboy1987
15 months ago

With the previous version, I hurried, sorry. That's more correct in my opinion.

#4 @earnjam
15 months 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.

@campusboy1987
15 months ago

the condition is corrected

#5 @SergeyBiryukov
15 months ago

  • Component changed from General to Posts, Post Types
  • Milestone changed from Awaiting Review to 4.9.9
  • Owner set to SergeyBiryukov
  • Status changed from assigned to reviewing

#6 @Presskopp
13 months ago

  • Keywords has-patch added

#7 @pento
13 months ago

  • Milestone changed from 4.9.9 to 5.0.1

#8 @pento
10 months ago

  • Milestone changed from 5.0.1 to 5.0.2

#9 @pento
10 months ago

  • Milestone changed from 5.0.2 to 5.0.3

#10 @ocean90
10 months ago

  • Milestone changed from 5.0.3 to Future Release
Note: See TracTickets for help on using tickets.