Adding CPT to Genesis Post

Community Forums Forums General Discussion Adding CPT to Genesis Post

This topic is: not resolved

This topic contains 9 replies, has 3 voices, and was last updated by  braddalton 3 months, 4 weeks ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #115626

    jholcombkw
    Member
    Post count: 11

    I am wanting to add a CPT to the homepage along with Posts. Currently we have Post which equal Cat-1 pulling on the homepage newest to oldest and I would like to mix in a CPT.

    The current code is on functions.php

    /*** Custom Post Byline */
    function custom_post_info($post_info) {
    	$post_info = 'By [post_author_posts_link]';
    	if (!is_single()) { $post_info .= '<a href="' . get_comments_link() . '" class="leave-comment">Leave a Comment</a>'; }
    	$post_info .= '<div class="post-date"><span class="month">[post_date format="M"]</span><span class="day">[post_date format="j"]</span>[post_comments zero="0" one="1" more="%"]</div>';
    	return $post_info;
    	}
    add_filter('genesis_post_info','custom_post_info',40);
    add_filter('genesis_post_info','do_shortcode',40);
    

    Current homepage php

    <?php
    remove_action( 'genesis_loop', 'genesis_do_loop' );
    add_action( 'genesis_loop', 'child_grid_loop_helper' );
    /** Add support for Genesis Grid Loop **/
    function child_grid_loop_helper() {
    
    	if ( function_exists( 'genesis_grid_loop' ) ) {
    		remove_action( 'genesis_before_post_content', 'generate_post_image', 5 );
    		genesis_grid_loop( array(
    			'cat'                   => 1,
    			'features'              => 1,
    			'feature_content_limit' => 0,
    			'grid_image_size'       => '',
    			'grid_content_limit'    => 0,
    			'more'                  => __('Continue','inspyr'),
    			
    		) );
    	} else {
    		genesis_standard_loop();
    	}
    
    }
    
    genesis();
    

    How would I add a CPT?

    • This topic was modified 4 months ago by  jholcombkw.
    • This topic was modified 4 months ago by  jholcombkw.
    http://theozarksconnection.com
    #115631

    braddalton
    Participant
    Post count: 10553
    #115639

    jholcombkw
    Member
    Post count: 11

    I tried the code, but nothing worked.

    #115642

    braddalton
    Participant
    Post count: 10553

    Where did you add the code?

    Did you change the post name in the code to the name of your CPT?

    The code is tested and works.


    #115646

    jholcombkw
    Member
    Post count: 11

    I add it to the bottom of my home.php and then tried it at the bottom of my functions.php. Yes I changed

    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() && !is_admin() ) {
    $query->set( 'post_type', array( 'post', 'your-cpt' ) );
    return $query;
     
        }
    }

    To

    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() && !is_admin() ) {
    $query->set( 'post_type', array( 'post', 'events' ) );
    return $query;
     
        }
    }
    #115652

    essaysnark
    Participant
    Post count: 342

    I don’t know how you have your CPT set up but it might need to be ‘event’ not ‘events’.

    #115723

    jholcombkw
    Member
    Post count: 11

    The CPT is events and it pull it. Where should I add the code?

    #115724

    braddalton
    Participant
    Post count: 10553

    Copy one of these snippets from the view raw link in the Gist and paste it at the end of your child themes functions file using a code editor.


    #115728

    jholcombkw
    Member
    Post count: 11

    Is there away to filter out only Category you want? Category id = 1 than pull to homepage?

    #115736

    braddalton
    Participant
    Post count: 10553

    Please mark this as resolved and start a new topic for your 2nd question.


Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.