I would rather use a full proper tax_query
here. The {tax}
syntax is depreciated according to the docs
A tax_query
is also better here as you will be dealing with an array of terms. When your URL is
http://www.myWebsiteURL.com/lessons
this means that all terms should be displayed. So this means that you need to use the full $validCats
array as query terms.
With this in mind, I have slightly changed your code to the following: (CAVEAT: Untested, and I assume you are using term slugs here, so I have set the field
parameter accordingly)
<?php
/* if URL query value is a valid category, get all lessons for that category.
If it is not a valid category (or not category is provided), get ALL lessons. */
$validCats = ['study-skills', 'time-management', 'math', 'tutoring', 'reading', 'online-learning'];
if ( isset( $_GET['lc'] ) && in_array( $_GET['lc'], $validCats ) ) {
$terms = $_GET['lc'];
} else {
$terms = $validCats;
}
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = [
'post_type' => 'lesson',
'post_status' => 'publish',
'paged' => $paged,
'tax_query' => [
[
'taxonomy' => 'subject',
'field' => 'slug',
'terms' => $terms
]
]
];
$lessons = new WP_Query($args);
?>