WordPress.org

Make WordPress Core

Ticket #12588: is_singular.3.diff

File is_singular.3.diff, 1.8 KB (added by scribu, 8 years ago)

check $wp_query->is_single too

  • wp-includes/query.php

     
    134134 * @param string|int $author Optional. Is current page this author.
    135135 * @return bool True if page is author or $author (if set).
    136136 */
    137 function is_author ($author = '') {
     137function is_author($author = '') {
    138138        global $wp_query;
    139139
    140140        if ( !$wp_query->is_author )
     
    169169 * @param string|array $category Optional.
    170170 * @return bool
    171171 */
    172 function is_category ($category = '') {
     172function is_category($category = '') {
    173173        global $wp_query;
    174174
    175175        if ( !$wp_query->is_category )
     
    398398 * @param mixed $page Either page or list of pages to test against.
    399399 * @return bool
    400400 */
    401 function is_page ($page = '') {
     401function is_page($page = '') {
    402402        global $wp_query;
    403403
    404404        if ( !$wp_query->is_page )
     
    518518        if ( !$wp_query->is_single )
    519519                return false;
    520520
    521         if ( empty( $post) )
     521        if ( empty($post) )
    522522                return true;
    523523
    524524        $post_obj = $wp_query->get_queried_object();
     
    541541 * @since 1.5.0
    542542 * @uses $wp_query
    543543 *
     544 * @param string|array $post_types Optional. Post type or types to check in current query.
    544545 * @return bool
    545546 */
    546 function is_singular() {
     547function is_singular($post_types = '') {
    547548        global $wp_query;
    548549
    549         return $wp_query->is_singular;
     550        if ( empty($post_types) )
     551                return $wp_query->is_singular;
     552
     553        $post_obj = $wp_query->get_queried_object();
     554
     555        return $wp_query->is_single && in_array($post_obj->post_type, (array) $post_types);
    550556}
    551557
    552558/**
     
    12261232         *
    12271233         * @param string|array $query
    12281234         */
    1229         function parse_query($query ) {
     1235        function parse_query($query) {
    12301236                if ( !empty($query) || !isset($this->query) ) {
    12311237                        $this->init();
    12321238                        if ( is_array($query) )