2

This wpmudev post sums up my feeling exactly about twenty fourteen:

Featured Content does not support custom post types – only posts are selected even if the custom post type supports the Tags taxonomy

I've added two CPT that share a custom taxonomy. I've tried tagging them without any luck, looked at inc/featured-content.php,js/slider.js and functions.php.

How can I add these post types so they display in the Featured Content slider on homepage?

related QA on WPSE

1 Answer 1

2

The twentyfourteen_get_featured_posts filter:

It took some digging, to figure out how the twentyfourteen_get_featured_posts filter is used in the TwentyFourteen theme ;-)


The featured content is fetched with:

$featured_posts = twentyfourteen_get_featured_posts();

but this function is only this single line:

return apply_filters( 'twentyfourteen_get_featured_posts', array() );

so where's the meat?


We find it in the Featured_Content class, starting with this line:

add_filter( $filter, array( __CLASS__, 'get_featured_posts' ) );

where $filter comes from:

$filter = $theme_support[0]['featured_content_filter'];

where:

$theme_support = get_theme_support( 'featured-content' );

In functions.php we find:

// Add support for featured content.
add_theme_support( 'featured-content', array(
    'featured_content_filter' => 'twentyfourteen_get_featured_posts',
    'max_posts' => 6,
) );

so we finally see that:

$filter === 'twentyfourteen_get_featured_posts';

Example:

To override the default featured content posts, you can then try this:

add_filter( 'twentyfourteen_get_featured_posts', function( $posts ){

    // Modify this to your needs:
    $posts = get_posts( array(
        'post_type'       => array( 'cpt1', 'cpt2' ),
        'posts_per_page'  => 6,
        'featured_tax'    => 'featured_term' 
    ) );

    return $posts;

}, PHP_INT_MAX );

The next step would be to connect it to the theme customizer and maybe cache it.

Hopefully you can continue the journey from here ;-)

3
  • ps: I just checked out the link provided by the OP, and I can see that the first part of my answer is somewhat redundant, since @Rarst already goes through similar steps to understand how this filter works. So check out his great answer ;-)
    – birgire
    Jun 19, 2014 at 0:41
  • 2
    Thanks for digging around. Your explanation is excellent. Btw, didn't know you could direct link to line numbers in github.
    – Danger14
    Jun 19, 2014 at 22:20
  • 1
    You're welcome. Yes I really like this github feature, makes life much easier ;-)
    – birgire
    Jun 19, 2014 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.