[wp-trac] [WordPress Trac] #19744: url_to_postid() doesn't reconise Custom post types

WordPress Trac wp-trac at lists.automattic.com
Thu Jan 5 10:00:29 UTC 2012


#19744: url_to_postid() doesn't reconise Custom post types
-----------------------------+--------------------
 Reporter:  feedmeastraycat  |       Owner:
     Type:  defect (bug)     |      Status:  new
 Priority:  normal           |   Milestone:  3.4
Component:  Query            |     Version:  3.3.1
 Severity:  normal           |  Resolution:
 Keywords:  needs-patch      |
-----------------------------+--------------------

Comment (by feedmeastraycat):

 Another way of doing it would be to patch this in url_to_postid():

 Before the "Look for matches." loop, add this:
 {{{
 $post_type_query_vars = array();
 foreach ( $GLOBALS['wp_post_types'] as $post_type => $t )
         if ( $t->query_var )
                 $post_type_query_vars[$t->query_var] = $post_type;
 }}}

 And then change this:
 {{{
 // Filter out non-public query
 global $wp;
 parse_str($query, $query_vars);
 $query = array();
 foreach ( (array) $query_vars as $key => $value ) {
         if ( in_array($key, $wp->public_query_vars) )
                 $query[$key] = $value;
         }
 }}}

 To this:
 {{{
 // Filter out non-public query vars
 global $wp;
 parse_str($query, $query_vars);
 $query = array();
 foreach ( (array) $query_vars as $key => $value ) {
         if ( in_array($key, $wp->public_query_vars) ) {
                 $query[$key] = $value;
                 if ( isset($post_type_query_vars[$key] ) ) {
                         $query['post_type'] = $post_type_query_vars[$key];
                         $query['name'] = $value;
                 }
         }
 }
 }}}

 Sorry. Don't know how to do patches here yet. :)
 But that makes url_to_postid() recognize custom post types anyway. Just
 like in WP::parse_query().
 (Copied code from there)

 I've tested this and it works fine. And CPT receives pingbacks whit this
 fix.

 So my original problem with CPT not receiving pingback seems to be valid.
 But the fix might be to make WP_Query understand CPT_Name => CPT_Slug. :)
 Thanks so far!

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19744#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list