S
S
soofftt912015-10-27 02:35:56
WordPress
soofftt91, 2015-10-27 02:35:56

How to make posts from a custom type can be put instead of the main page of the blog?

Hello.
Created a custom post type (function register_post_type();). How can I make these posts can be put instead of the main page through the wp settings. By default, only "pages" can be selected there.
04935dcece5d41349d4dcfb01e064858.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2015-10-27
@soofftt91

Through the settings, as far as I know, no way. However, this is easily done through code:

function t260557_cpt_on_home( $query ) {
    if( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'post_type', 'ВАШ_POST_TYPE' );
    }
}
add_action( 'pre_get_posts', 't260557_cpt_on_home' );

You might $query->is_home()need to use $query->is_front_page().
Use this code in functions.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question