Custom Post type & Post on Homepage

Community Forums Forums General Discussion Custom Post type & Post on Homepage

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  braddalton 3 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #104122

    jholcombkw
    Member
    Post count: 10

    I am wanting to be able to use a custom post type call “events” mixed in with my post on my homepage. I would like to make it where only come of the “events” go to the homepage like I do with my post. To have my post show up it much be cat “featured”. Below was the code I was trying. It will pull all the events in no just the ones I want.

    add_filter( ‘pre_get_posts’, ‘my_get_posts’ );

    function my_get_posts( $query ) {

    if ( is_home() && $query->is_main_query() )
    $query->set( ‘post_type’, array( ‘post’, ‘events’ ) );

    return $query;
    }

    #104124

    braddalton
    Participant
    Post count: 9412

    You could try adding.
    [php]
    $query->set(‘post__in’, array( 1,2,3,4,5 ) );
    [/php]

    Please paste your code in a Github Gists before embedding in a web page as it will break the code.

    Otherwise you may have to use a new WP_Query with custom loop


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

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

You must be logged in to reply to this topic.