Forum

Thread tagged as: Question, Blog

Filter blog entries by Post Type or section

Hi Drew, is it possible to do this?

I've created the facility for contributors to point to one of two places on the site - their own blog stream and a front page timeline.

Due to the way that the posts are formatted for each section, the authors have to choose a Post Type before they start, as each will offer a different combination of block types.

Problem is, when an author posts to the timeline, the post also appears in their blog stream - so I'd like to filter out timeline posts in their blog pages, and only show default post types there.

My query for the timeline posts is:

<?php perch_blog_custom(array(
    'filter' => 'month-selector',
    'match' => 'eq',
    'value' => 'apr',
    'sort' => 'postDateTime',
    'sort-order' => 'ASC',
    'count' => '50',
    'template' => 'posts/post_timeline.html'
  )); ?>

and my query for the blog pages is (currently filtered by author):

<?php perch_blog_custom(array(
    'filter' => 'authorSlug',
    'match' => 'eq',
    'value' => 'megan-broadmeadow',
    'sort' => 'postDateTime',
    'sort-order' => 'DESC',
    'template' => 'post_in_list.html',
  )); ?>

I've tried doing the following to prevent Timeline post types appearing:

 <?php perch_blog_custom(array(
    'filter' => array(
      array(
       'filter' => 'authorSlug',
       'match' => 'eq',
       'value' => 'louise-hobson'
      ),
      array(
        'filter' => 'postType',
        'match' => 'eq',
        'value' => 'default'
      )
    ),
    'sort' => 'postDateTime',
    'sort-order' => 'DESC',
    'template' => 'post_in_list.html',
  )); ?>

but that doesn't work - I guess it's not possible to filter by post type (section doesn't work either).

Any suggestions on how to keep those timeline posts out of the blog area? I know I could introduce another checkbox to filter by, but it's another step for the authors to remember and I don't want to confuse things for them if there's a simpler way.

Thanks, Dave

David Shepherd

David Shepherd 0 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

You can filter by section in perch_blog_custom using the section option and the section slug.

Fantastic, thanks Rachel!