Skip to content

Instantly share code, notes, and snippets.

@Viper007Bond
Created March 28, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Viper007Bond/797685e2ef6e75e7289f to your computer and use it in GitHub Desktop.
Save Viper007Bond/797685e2ef6e75e7289f to your computer and use it in GitHub Desktop.
Include pages in category archive pages
<?php
/**
* Copy paste the below code into your theme's functions.php file.
* You could add it to a plugin instead, but it's just easier to
* add it to your theme's functions.php. The only drawback to this
* is if you switch themes, this functionality will stop working.
*
* --Alex Mills
* Questions? Contact me: http://www.viper007bond.com/contact/
*/
// Before the normal database query runs, change its arguments to include pages in the results.
add_filter( 'pre_get_posts', 'jamesbradley_include_pages_in_category_archives' );
function jamesbradley_include_pages_in_category_archives( $query ) {
if (
// Only modify the main database query
$query->is_main_query()
// Only modify the category archives page
&& $query->is_category()
) {
// Set the post type to look for to both posts and pages
$query->set( 'post_type', array( 'post', 'page' ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment