Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have used to below function to register a new 'guide' content type:

add_action( 'init', 'guide_post_type' );
function guide_post_type() {
register_post_type('guides', 
    array(  
        'label' => 'Guides',
        'description' => '',
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => array('slug' => 'guide'),
        'query_var' => true,
        'has_archive' => true,
        'exclude_from_search' => false,
        'supports' => array('title','editor','excerpt','comments','thumbnail','author',),
        'labels' => array (
            'name' => 'Guides',
            'singular_name' => 'Guide',
            'menu_name' => 'Guides',
            'add_new' => 'Add Guide',
            'add_new_item' => 'Add New Guide',
            'edit' => 'Edit',
            'edit_item' => 'Edit Guide',
            'new_item' => 'New Guide',
            'view' => 'View Guide',
            'view_item' => 'View Guide',
            'search_items' => 'Search Guides',
            'not_found' => 'No Guides Found',
            'not_found_in_trash' => 'No Guides Found in Trash',
            'parent' => 'Parent Guide',
            ),
    ) 
);
}

I want to display these posts on the homepage of my blog along with normal posts. To do that I have created a new home.php file with the below code:

remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'custom_homepage_loop' );

function custom_homepage_loop() {
global $paged;
global $query_args;
$args = array(
    'post_type' => array('post','guide')
);

genesis_custom_loop( wp_parse_args($query_args, $args) );
}

genesis();

However, I am still unable to see any guide post types on my homepage.

Any suggestions?

share|improve this question
    
Are you referring to your home page or front page? –  Brad Dalton Feb 28 at 2:35
add comment

3 Answers

In your child themes functions file:

add_action( 'pre_get_posts', 'wpsites_add_custom_post_types_to_loop' );

function wpsites_add_custom_post_types_to_loop( $query ) {

if ( is_home() && $query->is_main_query() ) {

$query->set( 'post_type', array( 'post', 'guides' ) );

return $query;

    }
}

This code will include your single CPT pages in your home page loop and display them on your posts page according to your Reading Settings which may or may not be your front page.

share|improve this answer
add comment

For displaying posts from a custom post type you can use a wp_query() object. In your case this is what you want :

<?php
    $arg = array(
            'post_type' => 'guide', // this can be an array : array('guide','guide1',...)
            'posts_per_page' => 10,
            'order' => 'DESC',
            // 'category_name' => 6
            'post_status' => 'publish'
            );
    $query = new WP_Query($arg);
    if ( $query->have_posts() ) : 
        while ( $query->have_posts() ) : $query->the_post(); 
        ?>
            <article>
                <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                <div><?php the_excerpt(); ?></div>
            </article>
        <?php
        endwhile;
    endif;
    wp_reset_query(); 
?> 
share|improve this answer
add comment

I had that issue as well with creating a new home page with the Genesis Framework. I found an easier solution was to create a new template and choose that template from the page attributes for my home page. Here's some more information.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.