Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#15771 closed defect (bug) (fixed)

url_to_postid() issues a notice on unmatching url's

Reported by: dd32 Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.1
Component: General Keywords:
Focuses: Cc:


url_to_postid() causes a Notice when the supplied url cannot be found on the site.

This is caused by #15770

Notice: Undefined property: WP_Query::$post in \wp-includes\rewrite.php on line 341

Change History (14)

comment:1 @dd324 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [16872]) Check to see if WP_Query has returned any posts before blindly accessing posts. Fixes #15771

comment:2 @scribu4 years ago

Shouldn't $query->is_singular be used instead?

comment:3 @dd324 years ago

  • Version set to 3.1

I considered that, But that matches Attachments as well, I felt it best to leave it how it currently is for now.

comment:4 @scribu4 years ago

Not always. See #14034

comment:5 @nacin4 years ago

Unless I missed something in #14034, is_singular == is_single
is_page == is_single is_page is_attachment. An attachment is always either is_single or is_page in addition to being is_attachment.

comment:6 @dd324 years ago

You're probably right then, Changing that to is_singular, or for that matter, anything which specifies we've hit a unique post object, would do.

comment:7 @dd324 years ago

(either of you 2 can commit that if you wish, I'm burried elsewhere)

comment:8 @scribu4 years ago

nacin, the source says otherwise:

$this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;


comment:9 follow-up: @nacin4 years ago

Right, I'm saying the source there is redundant. is_single XOR is_page will always be true when is_attachment is true. The last part is dead code. (That said, I wouldn't remove it, because it explains what is_singular is supposed to match.)

Again, I may have missed something, but I went through every is_attachment flag in WP_Query and found every one of them to also be paired with is_single or is_page.

I think this ticket is fine as is, also.

comment:10 @scribu4 years ago

(In [16877]) Use is_singular in url_to_postid(). See #15771

comment:11 @scribu4 years ago

(In [16878]) Remove excess comments from url_to_postid(). See #15771

comment:12 in reply to: ↑ 9 @scribu4 years ago

If we have a general, atomic flag for a particular purpose, I think it should be used. Maybe even use is_singular().

comment:13 @scribu4 years ago

Actually, what if we drop the is_singular flag altogether and use is_singular() everywhere?

Note: See TracTickets for help on using tickets.