The cat_drop
setting is empty because your drop-down menu, or the select
field doesn’t have the proper name
value, so PHP isn’t receiving the selected option/value. So to fix the issue, just add the proper name
value to the select
field:
<!-- Wrapped for brevity. -->
<select
name="<?php echo $this->get_field_name( 'cat_drop' ); ?>"
id="<?php echo $this->get_field_id( 'cat_drop' ); ?>"
>
But then, there are other issues in your code:
-
In the
cat_drop
drop-down menu, the options should be the term slug, but you currently set it to the term name. So be sure to use the term slug instead:<!-- Note the $item->slug --> <option value="<?php echo $item->slug;?>"><?php echo esc_html( $item->name ); ?></option>
-
In the widget display callback (
widget()
), you’re overriding the$args
variable when you do$args = array('post_type' => 'game', 'gamecategory' =>$selected_cat);
and that results in a PHP notice with theecho $args['after_widget'];
at the end of the function, because the$args['after_widget']
is now undefined. And when it’s undefined, the widget container will not be closed and that could result in layout issues, despite browsers are basically “smart” and would-auto close the container.So you should rename one of the
$args
, maybe the one that you use withWP_Query
. -
Using
esc_html__()
on an empty string is pointless:esc_html__( '', 'prisma' )
. So change those to just''
. -
This is just a personal note.. Could you please, improve the formatting of your code? E.g. Get rid of those unnecessary blank lines and use tab for indentation. Because a good code is not just one that works, but also clean because it would be easy for other developers to maintain or work with the code. 🙂