Make WordPress Core

Ticket #26744: 26744.diff

File 26744.diff, 2.4 KB (added by obenland, 11 years ago)
  • wp-content/themes/twentyfourteen/inc/featured-content.php

     
    150150         * @return array Array of post IDs.
    151151         */
    152152        public static function get_featured_post_ids() {
    153                 // Return array of cached results if they exist.
     153                // Get array of cached results if they exist.
    154154                $featured_ids = get_transient( 'featured_content_ids' );
    155                 if ( ! empty( $featured_ids ) ) {
    156                         return array_map( 'absint', (array) $featured_ids );
    157                 }
    158155
    159                 $settings = self::get_setting();
     156                if ( false === $featured_ids ) {
     157                        $settings = self::get_setting();
     158                        $term     = get_term_by( 'name', $settings['tag-name'], 'post_tag' );
    160159
    161                 // Return sticky post ids if no tag name is set.
    162                 $term = get_term_by( 'name', $settings['tag-name'], 'post_tag' );
    163                 if ( $term ) {
    164                         $tag = $term->term_id;
    165                 } else {
    166                         return self::get_sticky_posts();
    167                 }
    168 
    169                 // Query for featured posts.
    170                 $featured = get_posts( array(
    171                         'numberposts' => $settings['quantity'],
    172                         'tax_query'   => array(
    173                                 array(
    174                                         'field'    => 'term_id',
    175                                         'taxonomy' => 'post_tag',
    176                                         'terms'    => $tag,
    177                                 ),
    178                         ),
    179                 ) );
     160                        if ( $term ) {
     161                                // Query for featured posts.
     162                                $featured = get_posts( array(
     163                                        'numberposts' => $settings['quantity'],
     164                                        'tax_query'   => array(
     165                                                array(
     166                                                        'field'    => 'term_id',
     167                                                        'taxonomy' => 'post_tag',
     168                                                        'terms'    => $tag,
     169                                                ),
     170                                        ),
     171                                ) );
    180172
    181                 // Return array with sticky posts if no Featured Content exists.
    182                 if ( ! $featured ) {
    183                         return self::get_sticky_posts();
    184                 }
     173                                if ( $featured ) {
     174                                        $featured_ids = wp_list_pluck( (array) $featured, 'ID' );
     175                                }
     176                        }
    185177
    186                 // Ensure correct format before save/return.
    187                 $featured_ids = wp_list_pluck( (array) $featured, 'ID' );
    188                 $featured_ids = array_map( 'absint', $featured_ids );
     178                        // Get sticky posts if no Featured Content exists.
     179                        if ( ! $featured_ids ) {
     180                                $featured_ids = self::get_sticky_posts();
     181                        }
    189182
    190                 set_transient( 'featured_content_ids', $featured_ids );
     183                        set_transient( 'featured_content_ids', $featured_ids );
     184                }
    191185
    192                 return $featured_ids;
     186                // Ensure correct format before return.
     187                return array_map( 'absint', (array) $featured_ids );
    193188        }
    194189
    195190        /**