Public Ticket #1298709
Adding Custom Post Type to Homepage Feed


  • Lance Baily started the conversation

    Hopefully this next one is a little easier. :) So,, I'm seeing if you have a better way of adding a custom post type to the homepage feed (or to any loop, really). The normal way I'd go about this is make a plugin and do something like:

    add_action( 'pre_get_posts', 'jobs_in_home_loop' );
    function jobs_in_home_loop( $query ) {
        if( $query->is_main_query() && $query->is_home() ) {
            $query->set( 'post_type', array( 'post', 'job') );

    But that doesn't work with this theme. Specifically, $query->is_main_query() isn't working... if I take that out. Then the nav vanishes. But adding in 'nav_menu_item' to the array then makes nav items show in the main loop and we obviously don't want that!

    I'm assuming there is some way this can be done in /functions/shortcodes/loop.php, etc. Please, assist!

  • Lance Baily replied

    So, in /functions/shortcodes/loop.php line ~line 164:
       args = array('posts_per_page' => $postsperpage, 'ignore_sticky_posts' => false);

    if I amend that to:
        args = array('posts_per_page' => $postsperpage, 'ignore_sticky_posts' => false, 'post_type' => array( 'post', 'job') );

    Then I properly get jobs-type posts to show on the homepage--great! Can you forsee that causing any issues? This seems pretty safe to me.

    Unfortunately, then clicking 'Load More' doesn't pull more jobs. Still trying to figure out what to amend to make this last part work.

  •  293
    Brian replied

    Engine uses a loop mechanism such that the loop is called with args from the various shortcodes, which you have figured out it appears. So the trick is to get the ajax functions to load the same args, and they are stored in the data attribute, so you'd need to figure out a way to modify those. Definitely a customization to the theme functionality...