Title: Custom type posts are missing
Last modified: August 22, 2016

---

# Custom type posts are missing

 *  Resolved [Yury](https://wordpress.org/support/users/telitsin/)
 * (@telitsin)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/custom-type-posts-are-missing/)
 * Timber does not show custom type posts in posts index page.
 * index.php:
 *     ```
       $context = Timber::get_context();
       $context['posts'] = Timber::get_posts();
       $context['foo'] = 'bar';
       $templates = array('index.twig');
       if (is_home()){
         array_unshift($templates, 'home.twig');
       }
       Timber::render($templates, $context);
       ```
   
 * functions.php:
 *     ```
       function register_post_types(){
         register_post_type( 'test',
           array(
             'labels' => array(
               'name' => __( 'test' ),
               'singular_name' => __( 'test' )
             ),
             'public' => true,
             'taxonomies' => array( 'post_tag', 'category' )
           )
         );
       }
       ```
   
 * [https://wordpress.org/plugins/timber-library/](https://wordpress.org/plugins/timber-library/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [jarednova](https://wordpress.org/support/users/jarednova/)
 * (@jarednova)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/custom-type-posts-are-missing/#post-5314588)
 * Hi Yury, by default WP only returns posts in those queries (the `get_posts` function
   inherits those WP defaults). You would need to do something like:
 *     ```
       $context['posts'] = Timber::get_posts('post_type=any');
       //or
       $context['posts'] = Timber::get_posts('post_type=test');
       ```
   
 *  Thread Starter [Yury](https://wordpress.org/support/users/telitsin/)
 * (@telitsin)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/custom-type-posts-are-missing/#post-5314601)
 * Hi, jarednova.
 * Thanks for the reply.
 * I found a way to add posts of different types to query:
 *     ```
       function test__pre_get_posts( $query ) {
         if( is_home() && is_main_query() ) {
           $query->set( 'post_type', array( 'post', 'test-post-type' ) );
         }
       }
       add_action( 'pre_get_posts', 'test__pre_get_posts' );
       ```
   
 *  Plugin Author [jarednova](https://wordpress.org/support/users/jarednova/)
 * (@jarednova)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/custom-type-posts-are-missing/#post-5314602)
 * yup, that’ll do it to!
 *  Thread Starter [Yury](https://wordpress.org/support/users/telitsin/)
 * (@telitsin)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/custom-type-posts-are-missing/#post-5314609)
 * One more way:
 * 1. Set different post types:
 *     ```
       $context['posts'] = Timber::get_posts();
       $context['slides'] = Timber::get_posts('post_type=slide');
       $context['videos'] = Timber::get_posts('post_type=gallery_video');
       ```
   
 * 2. Merge arrays in twig template:
 *     ```
       {% set posts = posts|merge(slides) %}
       {% set posts = posts|merge(videos) %}
       ```
   
 *  Thread Starter [Yury](https://wordpress.org/support/users/telitsin/)
 * (@telitsin)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/custom-type-posts-are-missing/#post-5314613)
 * I have discovered that
 *     ```
       $context['posts'] = Timber::get_posts('post_type=any');
       //or
       $context['posts'] = Timber::get_posts('post_type=test');
       ```
   
 * does not work for taxonomy archives. This way WP outputs all posts I have without
   filtering them for the taxonomy.
 * So in my case only this code works:
 *     ```
       function test__pre_get_posts( $query ) {
         if( !( is_post_type_archive() || is_admin() )  ) {
           $query->set( 'post_type',
             array(
               'post', 'page', 'nav_menu_item', // Keep default types
               'test-post-type',
               'test-post-type-2'
             )
           );
         }
       }
       add_action( 'pre_get_posts', 'test__pre_get_posts' );
       ```
   
 * NB! To preserve pages and menus to be shown `post`, `page`, `nav_menu_item` types
   have to be included.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Custom type posts are missing’ is closed to new replies.

 * ![](https://ps.w.org/timber-library/assets/icon-256x256.png?rev=1482054)
 * [Timber](https://wordpress.org/plugins/timber-library/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/timber-library/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/timber-library/)
 * [Active Topics](https://wordpress.org/support/plugin/timber-library/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/timber-library/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/timber-library/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Yury](https://wordpress.org/support/users/telitsin/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/custom-type-posts-are-missing/#post-5314613)
 * Status: resolved