[wp-trac] [WordPress Trac] #16025: Page and custom taxonomy query var 404s

WordPress Trac wp-trac at lists.automattic.com
Thu Mar 3 02:17:24 UTC 2011


#16025: Page and custom taxonomy query var 404s
--------------------------+-----------------------------
 Reporter:  duck_         |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Query         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  close         |
--------------------------+-----------------------------

Comment (by anmari):

 More info;
 I decided not to be selfish and lazy and dig into the 3.1 code.
 If one were to decide one had a page on a page_id and not add in the
 taxonomies and categories, the change would have to be somewhere in
 query.php between lines 2100 and 2113.

 If pages could have taxonomies and catgeories (can they?) then it would
 make sense to leave code as is and users would have to make sure that they
 added the necessary taxos and cats to the page. (I got shortcode in a post
 working as before by doing that for a post).

 Anyway I come up with a fix that seems adequate for my purposes using
 action that is called at top that section.


 {{{
 add_action ('pre_get_posts', 'a_page_is_a_page_we_need_no_more');

 function a_page_is_a_page_we_need_no_more($q) {
 // removes category and taxonomy query vars from page queries
 // the logic being that if we are querying a page, then categories and
 taxonomies are not relevant and can be ignored.
 // the category and taxonomy are still there to be used by the event
 shortcode logic.
 // possibly one should also look at unsetting the more sophisticated
 tag_in etc vars, but for now this will do me

         if (isset($q->query_vars) and  $q->query_vars['page_id']) {  //
 unset categoreids and taxos
                 $opt  = get_option( 'amr-event-taxonomies' );
                 if (!empty ($opt)) {
                         if ( is_array( $opt['taxonomies'] ) ) {
                                 foreach( $opt['taxonomies'] as $key =>
 $taxonomy ) {
                                         if (!empty
 ($taxonomy['posttype'])) // ie we are using it somewhere for our events
 unset($q->query_vars[$taxonomy['name']]);
                                         }
                         unset($q->query_vars['category_name']);
                         }
                 }
         }
         return($q);
 }




 }}}

 Now just to figure out why the metabox is not appearing and custom columns
 in the edit screen!

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


More information about the wp-trac mailing list