$post_ids, 'posts_per_page' => count( $post_ids ), 'post_type' => self::$post_types, 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_key' => 'pb_feature_index', ) ); } else { $joy_featured_posts = get_posts( array( 'include' => $post_ids, 'posts_per_page' => count( $post_ids ), 'post_type' => self::$post_types, ) ); } return $joy_featured_posts; } /** * Get featured post IDs * * This function will return the an array containing the post IDs of all * featured posts. * * Sets the "featured_content_ids" transient. * * @return array Array of post IDs. */ public static function get_featured_post_ids() { // Return array of cached results if they exist. //$featured_ids = get_transient( 'pb_featured_content_ids' ); if ( ! empty( $featured_ids ) ) { return array_map( 'absint', /** * Filter the list of Featured Posts IDs. * * @module theme-tools * * @since 2.7.0 * * @param array $featured_ids Array of post IDs. */ apply_filters( 'joy_featured_content_post_ids', (array) $featured_ids ) ); } // Return empty array if no tag name is set. $term = get_term_by( 'name', self::$tag_name, 'post_tag' ); if ( ! $term ) { $term = get_term_by( 'id', self::$tag_name, 'post_tag' ); } if ( $term ) { $tag = $term->term_id; } else { return apply_filters( 'joy_featured_content_post_ids', array() ); } // Back compat for installs that have the quantity option still set. $quantity = self::$max_posts; // Query for featured posts. if (self::$post_order == 'custom') { $featured = get_posts( array( 'numberposts' => $quantity, 'post_type' => self::$post_types, 'tax_query' => array( array( 'field' => 'term_id', 'taxonomy' => 'post_tag', 'terms' => $tag, ), ), 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_key' => 'pb_feature_index', ) ); } else { $featured = get_posts( array( 'numberposts' => $quantity, 'post_type' => self::$post_types, 'tax_query' => array( array( 'field' => 'term_id', 'taxonomy' => 'post_tag', 'terms' => $tag, ), ), ) ); } // Return empty array if no featured content exists. if ( ! $featured ) { return apply_filters( 'joy_featured_content_post_ids', array() ); } // Ensure correct format before save/return. $featured_ids = wp_list_pluck( (array) $featured, 'ID' ); $featured_ids = array_map( 'absint', $featured_ids ); set_transient( 'joy_featured_content_ids', $featured_ids ); return apply_filters( 'joy_featured_content_post_ids', $featured_ids ); } }