Skip to content

Instantly share code, notes, and snippets.

@NichlasB
Last active June 22, 2017 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NichlasB/47f6aa506477724d0beb042af6798659 to your computer and use it in GitHub Desktop.
Save NichlasB/47f6aa506477724d0beb042af6798659 to your computer and use it in GitHub Desktop.
Display Chosen Categories on WordPress Blog Page
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* display-chosen-categories.php
*/
//* Display only chosen categories on blog page
function cf_display_chosen_categories( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '5 3');
}
}
add_action( 'pre_get_posts', 'cf_display_chosen_categories' );
@NichlasB
Copy link
Author

Exclude chosen categories from blog page: https://gist.github.com/NichlasB/e50134cc6235dc1b91c4aa6537f0e841

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment