Filtering out specific post formats from certain pages

I’d like to filter out certain post formats from certain page templates. Specifically, I’d like to exclude link post types from the front page, so I can put them in a side bar, but still keep them in archive pages. I’d also like to exclude them from a variant of an RSS feed (but not all RSS feeds).

I know I can do this by editing the templates, but is there a way to do this via a plugin alone?

Related posts

Leave a Reply

1 comment

  1. Since you’re going to be modifying either the Loop Query or the Loop output, I would recommend modifying the appropriate template files directly.

    To filter out Posts with the “quote” Post Format, simply wrap your Loop output (inside of the if-have-posts-while-have-posts-the-post) with:

    if ( ! has_post_format( 'quote' ) ) {
        // Loop output goes here
    }
    

    Then, in your sidebar, you would create a custom Loop, e.g.:

    $linkpostargs = array(
        'tax_query' => array(
            'taxonomy' => 'post_format',
            'field'    => 'slug',
            'terms'    => array( 'post-format-link' ),
            'operator' => 'IN'
        )
    );
    $link_posts = get_posts( $linkpostargs );
    
    foreach ( $link_posts as $link_post ) {
        // Custom Loop output goes here
    }
    

    (H/T Michael Fields for the query args)

    I honestly don’t know how you’d replicate this functionality using a Plugin alone.