For the first part of your question, a pre_get_posts
hook is all you would need. This code should work, providing you are using the default “Latest Posts” setting as your front page (Settings > Reading).
add_action( 'pre_get_posts', 'se132019_home_page_all_post_types' );
function se132019_home_page_all_post_types( $query ) {
if ( ! is_admin() $query->is_main_query() && $query->is_posts_page() ) {
$query->set( 'post_type', 'any' );
}
}
If you are using a custom WP_Query, just add 'post_type' => 'any'
as an argument.
The second piece is a personal preference for you – you could just house all posts in Posts, and display them differently depending on the terms (categories) they are attached to. Otherwise, you would need to do the following 2 things:
- Add your custom post types (Job Listings) to the
category
taxonomy. This can be done when registering the post type usingtaxonomies
argument, or using register_taxonomy_for_object_type. - hook into the
save_post
method, check to see if the post was attached to any Categories. If not, manually assign it to the proper category, depending on which post type it was.
EDIT::
your first couple lines should look like the following. When a WP_Query object is created, it automatically calls the query()
function. You are calling it a second time, passing it new arguments.
<?php
$args = array(
'post_type' => 'any',
'posts_per_page' => 3
);
$recent = new WP_Query($args);