#25136 closed defect (bug) (invalid)
url_to_postid() fails but get_page_by_path() works, on a Woocommerce page
Reported by: | adiant | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.6 |
Component: | Query | Keywords: | |
Focuses: | Cc: |
Description
For at least one of the pages that the Woocommerce plugin creates, at /shop/, url_to_postid() returns a zero, yet get_page_by_path() works.
Attached file shows the var_dump of the output of the two functions, and the php source that created the output. The results are identical when Permalinks either default (?p=123) or are set to /%postname%/
Because my Plugin's user who reported this, and the test shown here, both were on localhost (Mac and Win 8) installs, I just repeated this test on commercial Linux-based web hosting, and got the same results, with both default (?p=123) and /%postname%/ Permalinks.
Attachments (1)
Change History (6)
#1
@
11 years ago
- Component changed from General to Query
/shop/
page in WooCommerce acts as an archive for "product" post type, not as a regular page. Here's some info from Debug Bar plugin:
Request: shop Query String: post_type=product Matched Rewrite Rule: shop/?$ Matched Rewrite Query: post_type=product
#2
@
11 years ago
You may be right, but it comes up as a regular page in the All Pages list in Admin, with a Page ID of 38. And I did a side-by-side comparison with the default Sample Page of a new WordPress install and couldn't find any differences in the get_page_by_path() data.
#3
@
11 years ago
get_page_by_path()
specifically looks for a page with the provided slug, while url_to_postid()
only returns the post/page ID if it resolves to a singular entity (which is not the case for a post type archive): tags/3.6/wp-includes/rewrite.php#L368.
This seems like expected behaviour to me, I don't see a bug here. I'd suggest using get_page_by_path()
if it makes more sense in your situation.
var_dump output