One of my goals for 2012 is to to get credit for a patch in the WordPress core. It feels like it would be neat. Nerdy… But neat.
This vacation week, when I was going to play Skyrim, but ended up watching all Alien movies on Bluray and coding some WordPress, I might have found my bug. A user in a WordPress dev Facebook group asked if anyone had received pingbacks on custom post types. He hadn’t and was starting to believe something was wrong within WP. I thought it sounded like a fun thing to investigate. So I did. And it turns out it is… I think.
The reason seams to be that the XML-RCP server uses a function called url_to_postid() to get the post ID from the pinged URL. So if the ping is for a regular post and the site is using permalinks it might be something like feedmeastraycat.net/2012/01/08/on-the-road-to-a-wordpress-core-patch/ in which case /2012/01/08/on-the-road-to-a-wordpress-core-patch/ is sent in and the post id is returned. The problem seams to be that it doesn’t handle custom post type urls.
If there is a CPT named “products” and you have a post with the slug/name “macbook” you might have the url test.com/products/macbook/. The url_to_postid() function goes through the rewrite rules and tries to find a match. Which it should do. It then creates a query for that match, which in this case looks like this:
Array
(
[products] => macbook
[page] =>
)
The problem here is that this query will fail. WP_Query requires a ‘post_type’ => CPT_Name parameter as well. It should look like this:
Array
(
[post_type] => products
[name] => macbook
)
During a regular page call, this is made in WP->parse_request() (here). Not in WP_Query.
Well. I created a ticket and I’ve also added a suggested patch. In a comment. Cause I don’t know how to do it as a real patch… I hope that I haven’t missed anything. And that the higher up:ers like my patch suggestion. It would be nice to get a patch in early and free up 2012 for new goals.


















