Add post_type to index.php

I search for an hour now without result. Does anyone can explain me how to show my custom post_type (dictionnaire) in the homepage (index.php). I use ‘Easy post type’ to add custom post types and I checked the “Query Var” checkbox. Please help…

The only posts that appears in my homepage are the regular one.

Related posts

Leave a Reply

1 comment

  1. It would be something like this (goes in functions.php or elsewhere, but not template):

    add_action( 'pre_get_posts', 'include_dictionnaire_in_home' );
    
    function include_dictionnaire_in_home( $query ) {
    
        if ( ! is_admin() && $query->is_main_query() && $query->is_home() ) {
            $query->set( 'post_type', array( 'post', 'dictionnaire' ) );
        }
    }
    

    Note that index.php template is not strictly home template. It is catch-all template that is used if no better hierarchy match is available. It’s just common for home because more specific template is rarely provided for it.