Created
March 28, 2015 21:19
-
-
Save Viper007Bond/797685e2ef6e75e7289f to your computer and use it in GitHub Desktop.
Include pages in category archive pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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