I have a template that lists posts by categories. It works great with the exception of categories with a space in their name.
I simply want to use a URL parameter to select the category and it only works if there is no space. Adding a %20 doesn't help.
It works great when the category is a single word but doesn't work when the category has a space. When I try to call it like this "https://url/?template=oneword" it's fine, when I try to call it with https://url/?firstword%20secondword" it's no good.
Using the slug doesn't work either; single word categories are fine and multi-word categories are blank (even though the slug is a single word).
Here's the template code I'm using:
$args = array(
'orderby' => 'name',
'parent' => 0,
'name' => $category_name
);
$categories = get_categories( $args );
foreach ($categories as $category) {
echo '<h2>'.$category->name.'</h2>';
echo '<ul>';
foreach (get_posts('cat='.$category->term_id) as $post) {
setup_postdata( $post );
echo '<li><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></li>';
}
echo '</ul>';
Any ideas?