Override twentyfourteen_get_featured_posts
-
Hello friends! I’ve created a child theme for twenty fourteen where I display the slider on every page. The site is divided into categories and so I need to display different featured content depending on which category the visitor sees (I’ve used a plugin to be able to add categories to pages as well as posts). The below code almost works.. it picks the correct featured content by category. BUT… it no longer respects the ‘Featured’ tag… I get ALL new posts in the slider and I still want to use the ‘Featured’ tag. What am I missing here? How do I change the code to have the normal behaviour of filtering content by the ‘Featured’ tag?
remove_filter( 'twentyfourteen_get_featured_posts' ); function twentyfourteen_child_get_featured_posts( $posts ){ global $post; $current_post_id = $post->ID; $show_posts = 5; //max number of posts returned to slider if( is_category() || is_archive() ){ $current_cat_id = get_query_var('cat'); $args = array('category' => $current_cat_id, 'post_type' => 'post', 'posts_per_page' => $show_posts); }elseif( is_page() || is_single() ){ $category = get_the_category($current_post_id); $current_cat_id = $category[0]->cat_ID; $args = array('category' => $current_cat_id, 'post_type' => 'post', 'posts_per_page' => $show_posts); }else{ $args = array( 'post_type' => 'post', 'posts_per_page' => $show_posts); } $new_post_array = get_posts( $args ); if ( count($new_post_array) > 0 ) { return $new_post_array; } else { return $posts; } } add_filter( 'twentyfourteen_get_featured_posts', 'twentyfourteen_child_get_featured_posts', 999, 1 );
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Override twentyfourteen_get_featured_posts’ is closed to new replies.