But this part is not executing →
$args = array( 'category_name' => $taxonomy, 'post_type' => 'video', 'posts_per_page' => -1,
It probably is. It's just wrong.
If you want to query posts by terms in a custom taxonomy you need to add a taxonomy query:
$args = array(
'post_type' => 'video',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'vcategory',
'field' => 'slug',
'terms' => $taxonomy,
)
)
);
This is explained, with examples, in the documentation. I'm going to implore you again to please read documentation.
Also, you're using the wrong $_POST
field. In wp_dropdown_categories()
you've given the field the name categoryfilter
, but are trying to get the value for taxonomy
. You need to set $taxonomy
like this:
$taxonomy = $_POST['categoryfilter];
Also, you shouldn't be using POST
for this type of request. You should be using GET
:
GET is used to request data from a specified resource.
POST is used to send data to a server to create/update a resource.
You're doing the first thing.