Skip to content

Instantly share code, notes, and snippets.

@kevinwhoffman
Created April 20, 2021 20:31
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 kevinwhoffman/7ae4f4541f62562e485ba4d05e8dd3b3 to your computer and use it in GitHub Desktop.
Save kevinwhoffman/7ae4f4541f62562e485ba4d05e8dd3b3 to your computer and use it in GitHub Desktop.
Filter WordPress category archive to display Learndash Lessons
<?php
function filter_category_archive_to_display_lessons( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
// Not a query for an admin page.
// It's the main query for a front end page of your site.
if ( is_category() ) {
// It's the main query for a category archive.
// Let's change the query for category archives to only display lessons.
$query->set( 'post_type', 'sfwd-lessons' );
}
}
}
add_action( 'pre_get_posts', 'filter_category_archive_to_display_lessons' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment