WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 17 months ago

#19744 closed defect (bug)

url_to_postid() doesn't reconise Custom post types — at Version 6

Reported by: feedmeastraycat Owned by:
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.3.1
Component: Query Keywords: has-patch
Focuses: Cc:

Description (last modified by dd32)

It seams like custom post type doesn't receive pingbacks. The XML-RPC server doesn't recognize the URL. The url_to_postid() function in rewrite.php finds a match, but the query is all wrong.

Example, if I set up custom post type with no "rewrite" in the arguments.
The URL to a custom post type would be: mydomain.com/custom_post_type_name/post-slug/

The function url_to_postid() finds a match on:

custom_post_type_name/([^/]+)(/[0-9]+)?/?$

The query is:

custom_post_type_name=$matches[1]&page=$matches[2]

But the query string (after WP_MatchesMapRegexp::apply()) looks like this:

custom_post_type_name=post-slug&page=

And the array that is sent into WP_Query looks like this:

Array
(
    [tips_and_trix] => finns-sjukt-manga-tips-har
    [page] => 
)

Which makes url_to_postid() return 0; And XML-RCP server returns IXR_Error(33, ...)

Change History (6)

comment:1 @dd323 years ago

  • Keywords reporter-feedback added

That all looks correct to me, the query strings and resulting array looks correct to me. The empty page field is expected.

I don't have the time to work out how to create a proper pingback request right now, but what does die($query->request); look like after line 340 of query.php (near the end of url_to_postid())

comment:2 @feedmeastraycat3 years ago

(I forgot to change my example "tips_and_trix" = "custom_post_type_name" and "finns-sjukt-manga-tips-har" = "post-slug)

die($query->request); after 340 of rewrite.php looks like this

SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND (wp_posts.ID = '0') AND wp_posts.post_type = 'page'  ORDER BY wp_posts.post_date DESC 

comment:3 @dd323 years ago

  • Keywords needs-patch added; reporter-feedback removed

and with a non-hierarchical post type I'm getting this:

SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private')  ORDER BY wp_posts.post_date DESC LIMIT 0, 10

So yes, something isn't working quite right there.

comment:4 @dd323 years ago

The cause is because WP_Query doesn't accept a CPT_Name => CPT_Slug field, you need to pass in the post_type field as well.

Our rewrite rules don't set that, instead, it's set during the Query parsing here: wp-includes/class-wp.php#L274

I don't quite understand why that code isn't within WP_Query myself.

comment:5 @feedmeastraycat3 years ago

Yes. Verified. Adding post_type into the query fixes it.

Does this mean something new has to be added to pingback_ping() in the XML-RPC server for it to be able to understand custom post types?

comment:6 @dd323 years ago

  • Component changed from XML-RPC to Query
  • Description modified (diff)
  • Milestone changed from Awaiting Review to 3.4
  • Summary changed from Custom post type doesn't receive pingback to url_to_postid() doesn't reconise Custom post types

My suggestion is that the logic from WP::parse_request() that I mentioned above should be moved into WP_Query.

I'm going to let another dev weigh in on that however, as I might be missing something related..

I've altered the fields to match the problem a bit more too.

Note: See TracTickets for help on using tickets.