[wp-trac] [WordPress Trac] #21790: When set a static front page WP main query isn't set correctly

WordPress Trac noreply at wordpress.org
Fri May 5 09:34:05 UTC 2017


#21790: When set a static front page WP main query isn't set correctly
--------------------------+-----------------------------
 Reporter:  markoheijnen  |       Owner:  SergeyBiryukov
     Type:  defect (bug)  |      Status:  assigned
 Priority:  normal        |   Milestone:  Future Release
Component:  Query         |     Version:  3.4.1
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:
--------------------------+-----------------------------

Comment (by Timbre Design):

 Agreed @justnorris I've noticed folks having issue with this since

 Per @jkohlbach it looks like he's found a workaround in the meantime (this
 is a WooCommerce specific example but will work elsewhere):

 {{{#!php
 <?php
 add_action( 'pre_get_posts', 'is_shop_workaround_demo', 1 );

 function is_shop_workaround_demo( $query ) {
     $front_page_id        = get_option( 'page_on_front' );
     $current_page_id      = $query->get( 'page_id' );
     $shop_page_id         = apply_filters( 'woocommerce_get_shop_page_id'
 , get_option( 'woocommerce_shop_page_id' ) );
     $is_static_front_page = 'page' == get_option( 'show_on_front' );

     // Detect if it's a static front page and the current page is the
 front page, then use our work around
     // Otherwise, just use is_shop since it works fine on other pages
     if ( $is_static_front_page && $front_page_id == $current_page_id  ) {
         error_log( 'is static front page and current page is front page'
 );
         $is_shop_page = ( $current_page_id == $shop_page_id ) ? true :
 false;
     } else {
         error_log( 'is not static front page, can use is_shop instead' );
         $is_shop_page = is_shop();
     }

     // Now we can use it in a conditional like so:
     if ($is_shop_page) {
         error_log( 'this is the shop page' );
     }
 }
 }}}

 [https://github.com/woocommerce/woocommerce/issues/10625]

--
Ticket URL: <https://core.trac.wordpress.org/ticket/21790#comment:30>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list