Skip to content

Commit

Permalink
Add query filters to taxonomy templates (#2530)
Browse files Browse the repository at this point in the history
* Add topic filter to learning pathway template

* Add level filter to learning pathway template

* Style the learning pathway header when loaded on level and topic tax pages

* Extract learning pathway header into a block for reuse

* Make Level filter a single select

* Correct filter titles

* Fix the header alignment config

* Fix undefined var in taxonomy content pattern

* Branch the level filter option creation at the template level

This turns out to be simpler than trying to use conditionals like is_tax within a single get_level_options function

* Enable clearing level selection using All option

* Modify filter input injection to handle single select filters

* Fix topic filtering on course and lesson archives

* Remove count limit on level filter

Even if there is only 1 level set, that can be used to filter vs all

* Remove language filter from Learning Pathway header

* Fix incorrect get_posts args

* Make getting options by post type safe

* Make see all links match level filter behaviour

* Fix filter padding
  • Loading branch information
adamwoodnz authored Jun 18, 2024
1 parent 950c381 commit 8e53021
Show file tree
Hide file tree
Showing 17 changed files with 584 additions and 124 deletions.
23 changes: 23 additions & 0 deletions wp-content/themes/pub/wporg-learn-2024/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// Block files
require_once __DIR__ . '/src/learning-pathway-cards/index.php';
require_once __DIR__ . '/src/learning-pathway-header/index.php';
require_once __DIR__ . '/src/search-results-context/index.php';
require_once __DIR__ . '/src/upcoming-online-workshops/index.php';
require_once __DIR__ . '/src/sensei-meta-list/index.php';
Expand All @@ -28,6 +29,7 @@
$args['has_archive'] = 'courses';
return $args;
} );
add_action( 'pre_get_posts', __NAMESPACE__ . '\modify_learning_pathways_query' );

/**
* Modify the single template hierarchy to use customised copies of the Sensei Course Theme templates.
Expand Down Expand Up @@ -277,3 +279,24 @@ function set_site_breadcrumbs( $breadcrumbs ) {

return $breadcrumbs;
}

/**
* Modify the main query.
* If the 'all' level filter is set in the query, remove it to return all posts.
*
* @param WP_Query $query The main query.
* @return WP_Query
*/
function modify_learning_pathways_query( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}

$level = $query->get( 'wporg_lesson_level' );

if ( 'all' === $level ) {
$query->set( 'wporg_lesson_level', '' );
}

return $query;
}
Loading

0 comments on commit 8e53021

Please sign in to comment.