[wp-trac] [WordPress Trac] #13535: get_query_var() not working as expected.

WordPress Trac wp-trac at lists.automattic.com
Tue May 25 17:17:38 UTC 2010


#13535: get_query_var() not working as expected.
--------------------------+-------------------------------------------------
 Reporter:  pmdci         |       Owner:  ryan                               
     Type:  defect (bug)  |      Status:  new                                
 Priority:  normal        |   Milestone:  Unassigned                         
Component:  Query         |     Version:  3.0                                
 Severity:  major         |    Keywords:  post_Type, get_query_var, is_single
--------------------------+-------------------------------------------------
 PLEASE SEE POST: [http://wordpress.org/support/topic/402823]

 I was trying to make my sidebar include a separate '''dashboard.php'''
 file based on the following conditionals:
 '''a)''' If I am on a single page; and
 '''b)''' If post is of type 'post'

 MichaelH proposed to me the following code as an example:

 {{{
 <?php
 $queried_post_type = get_query_var('post_type');
 if ( is_single() && 'hotel' ==  $queried_post_type ) {
   echo 'this single view is of a post type hotel';
 }
 ?>
 }}}

 And this is what I need to achieve in my sidebar:

 {{{
 <?php // get stats dashboard
 $queried_post_type = get_query_var('post_type');
   if ( is_single() && 'post' ==  $queried_post_type ) { include
 'dashboard.php'; } ?>
 }}}

 However, get_query_var doesn't return me any value. Besides trying to use
 it in my sidebar as I mentioned above, for troubleshooting I also tried
 this code inside the loops of  both my theme's '''index.php''' and
 '''single.php''' files. This is the simple code I tried inside my loops
 for debugging:

 {{{
 <?php if (have_posts()) : while (have_posts()) : the_post();
   $queried_post_type = get_query_var('post_type');
   echo $queried_post_type; ?>
 }}}

 But echo $queried_post_type doesn't return me any value. I tried <php echo
 $queried_post_type; ?> everywhere in my '''index.php''' and
 '''single.php''' but it never returned the values.

 Quoting MichaelH, he also believes this might be a bug. So he suggested
 that I raised this ticket (it is my first time, so be gentle :-] )

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/13535>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list