Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#15771 closed defect (bug) (fixed)

url_to_postid() issues a notice on unmatching url's

Reported by: dd32's profile 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)

#1 @dd32
13 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

#2 @scribu
13 years ago

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

#3 @dd32
13 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.

#4 @scribu
13 years ago

Not always. See #14034

#5 @nacin
13 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.

#6 @dd32
13 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.

#7 @dd32
13 years ago

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

#8 @scribu
13 years ago

nacin, the source says otherwise:

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

#9 follow-up: @nacin
13 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.

#10 @scribu
13 years ago

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

#11 @scribu
13 years ago

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

#12 in reply to: ↑ 9 @scribu
13 years ago

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

#13 @scribu
13 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.