Skip to content

Instantly share code, notes, and snippets.

@CapWebSolutions
Created February 7, 2018 23:02
Show Gist options
  • Select an option

  • Save CapWebSolutions/bbe188af1c0691da9e9634646b49275c to your computer and use it in GitHub Desktop.

Select an option

Save CapWebSolutions/bbe188af1c0691da9e9634646b49275c to your computer and use it in GitHub Desktop.
Two functions to add CPT archives into the mix for post archives and front page loops.
add_filter( 'pre_get_posts', 'prefix_cpk_show_cpt_archives' );
add_action( 'pre_get_posts', 'prefix_cpk_add_custom_post_types_to_loop' );
/**
* prefix_cpk_show_cpt_archives - Display job posting entires on taxonomy archive pages
*
* @param [type] $query
* @return void
*/
function prefix_cpk_show_cpt_archives( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'nav_menu_item', 'job_posting'
));
return $query;
}
}
/**
* prefix_cpk_add_custom_post_types_to_loop - Add JobPosting CPT to front page loop.
*
* @param [type] $query
* @return void
*/
function prefix_cpk_add_custom_post_types_to_loop( $query ) {
if ( is_home() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'job_posting' ) );
return $query;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment