Custom archive page with Timber RSS Feed Issue
Asked Answered
B

1

6

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);
 });
Biparty answered 1/3, 2016 at 12:27 Comment(2)
checkout my updated answer below....Expectant
Never use query_postsBarcelona
E
3

@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 );
Expectant answered 4/3, 2016 at 3:24 Comment(2)
moving the post reset to after the initial post listing helps as it no longer shows a broken feed. But i guess I could be even more specific; I wanted the feed to be the list of posts and not the override page. Sounds like a wordpress thing as opposed to timber. ThanksBiparty
I've updated the issue with a new finding. Any further help would be great :)Biparty

© 2022 - 2024 — McMap. All rights reserved.