Custom archive page with Timber RSS Feed Issue

I’ve built a custom archive page within WordPress using Timber and the Route method. The page works well and shows a combination of Custom Post Types but the feed at {url}/feed doesn’t exist.

note: Previous answer has been edited to remove confusing side issues.

// create CPT (x 3)
register_post_type($name, array(
  'label' => 'custom1',
  'public' => true,
  'capability_type' => 'page',
  'supports' => array( 'title', 'author', 'excerpt', 'revisions', 'thumbnail'),
  'taxonomies' => array('post_tag'),
  'has_archive' => true
));

// CPT route
Routes::map('test/filter/:filter', function($params){
    $query = array(
      'post_type' => array('custom1', 'custom2', 'custom3' )
    );
    $filter = $params;
    Routes::load('archive.php', $filter, $query, 200);
});

// paging CPT route
Routes::map('test/filter/:filter/page/:page', function($params){
    $query = array(
      'post_type' => array('custom1', 'custom2', 'custom3' ),
      'paged' => intval($params['page'])
    );
    $filter = $params;
    Routes::load('archive.php', $filter, $query, 200);
 });

Related posts

1 comment

  1. @sidonaldson: Ahhhh now I realize what you’re looking for! Yes, this happens at the WP level, not Timber

    add_action( 'pre_get_posts', function ( $query ) {
        if ( $query->is_main_query() && !is_admin() && is_post_type_archive('agency')) {
            $query->set( 'post_type', array('post', 'custom', 'custom2') );
        }
    } );    
    

    Previous answer….

    @sidonaldson — this is an untested answer, but here’s what to give a shot to:

    query_posts is basically the WordPress equivalent of a sledge hammer that will affect RSS, pagination and everything else. Here’s what should work…

    $posts_query = array(
        'post_type' => array('post', 'custom', 'custom' ),
        'tag__in' => $tag_array,
        'orderby' => 'date',
        'post_status' => 'publish',
        'paged' => $paged
    );
    // First let's get this set for pagination
    query_posts($posts_query);
    $context['posts'] = Timber::get_posts($posts_query);
    $context['pagination'] = Timber::get_pagination();
    
    // now let's use it to hit RSS
    $post = new TimberPost('override_page_slug');
    query_posts(array( 'p' => $post->ID ));
    $context['post'] = $post;
    
    Timber::render( 'page-override_page_slug.twig', $context );
    

Comments are closed.