WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 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:

Description

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 dd323 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 scribu3 years ago

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

comment:3 dd323 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 scribu3 years ago

Not always. See #14034

comment:5 nacin3 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 dd323 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 dd323 years ago

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

comment:8 scribu3 years ago

nacin, the source says otherwise:

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

http://core.trac.wordpress.org/browser/trunk/wp-includes/query.php?rev=16854#L1404

comment:9 follow-up: nacin3 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 scribu3 years ago

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

comment:11 scribu3 years ago

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

comment:12 in reply to: ↑ 9 scribu3 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 scribu3 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.