Make WordPress Core

Opened 6 years ago

Last modified 5 years 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:


The query is:


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


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

    [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)

#1 @dd32
6 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())

#2 @feedmeastraycat
6 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 

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

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

#5 @feedmeastraycat
6 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?

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