Make WordPress Core

Ticket #26744: 26744.3.diff

File 26744.3.diff, 2.4 KB (added by lancewillett, 11 years ago)

Use correct variable for featured IDs

  • wp-content/themes/twentyfourteen/inc/featured-content.php

     
    151151         * @return array Array of post IDs.
    152152         */
    153153        public static function get_featured_post_ids() {
    154                 // Return array of cached results if they exist.
     154                // Get array of cached results if they exist.
    155155                $featured_ids = get_transient( 'featured_content_ids' );
    156                 if ( ! empty( $featured_ids ) ) {
    157                         return array_map( 'absint', (array) $featured_ids );
    158                 }
    159156
    160                 $settings = self::get_setting();
     157                if ( false === $featured_ids ) {
     158                        $settings = self::get_setting();
     159                        $term     = get_term_by( 'name', $settings['tag-name'], 'post_tag' );
    161160
    162                 // Return sticky post ids if no tag name is set.
    163                 $term = get_term_by( 'name', $settings['tag-name'], 'post_tag' );
    164                 if ( $term ) {
    165                         $tag = $term->term_id;
    166                 } else {
    167                         return self::get_sticky_posts();
    168                 }
     161                        if ( $term ) {
     162                                // Query for featured posts.
     163                                $featured_ids = get_posts( array(
     164                                        'fields'           => 'ids',
     165                                        'numberposts'      => self::$max_posts,
     166                                        'suppress_filters' => false,
     167                                        'tax_query'        => array(
     168                                                array(
     169                                                        'field'    => 'term_id',
     170                                                        'taxonomy' => 'post_tag',
     171                                                        'terms'    => $term->term_id,
     172                                                ),
     173                                        ),
     174                                ) );
     175                        }
    169176
    170                 // Query for featured posts.
    171                 $featured = get_posts( array(
    172                         'numberposts' => self::$max_posts,
    173                         'tax_query'   => array(
    174                                 array(
    175                                         'field'    => 'term_id',
    176                                         'taxonomy' => 'post_tag',
    177                                         'terms'    => $tag,
    178                                 ),
    179                         ),
    180                 ) );
     177                        // Get sticky posts if no Featured Content exists.
     178                        if ( ! $featured_ids ) {
     179                                $featured_ids = self::get_sticky_posts();
     180                        }
    181181
    182                 // Return array with sticky posts if no Featured Content exists.
    183                 if ( ! $featured ) {
    184                         return self::get_sticky_posts();
     182                        set_transient( 'featured_content_ids', $featured_ids );
    185183                }
    186184
    187                 // Ensure correct format before save/return.
    188                 $featured_ids = wp_list_pluck( (array) $featured, 'ID' );
    189                 $featured_ids = array_map( 'absint', $featured_ids );
    190 
    191                 set_transient( 'featured_content_ids', $featured_ids );
    192 
    193                 return $featured_ids;
     185                // Ensure correct format before return.
     186                return array_map( 'absint', $featured_ids );
    194187        }
    195188
    196189        /**