Use output of wp_dropdown_categories($args)

Please be gentle, I'm new to all this coding! I have finally worked out how to get a frontend dropdown field allowing me to select from EDD categories (I got this from the Codex):

div class="gallery-row"
  li id="categories"
    h2?php _e( 'Categories:' ); ?/h2
    form id="category-select" class="category-select" action="?php echo esc_url( home_url( '/' ) ); ?" method="get"
      ?php $args = array(
        'taxonomy' = 'download_category', // EDD custom post type Taxonomy
        'order'    = 'ASC' // Order of the list
      );
      wp_dropdown_categories($args); ?
      input type="submit" name="submit" value="view" /
    /form
  /li
/div

This is my original code,'selecttaxonomy' is a ACF taxonomy field (and only appears on the backend):

div class="content clearfix"div class="gallery-row2"
  ?php
  $current_page = get_query_var('paged'); // Retrieving the data
  $per_page = get_option('posts_per_page');
  $offset = $current_page  0 ? $per_page * ($current_page -1) : 0;
  $taxval = get_field('selecttaxonmy');

  $product_args = array(
    'post_type'         = 'download',
    'posts_per_page'    = $per_page,
    'offset'            = $offset,
    'download_category' = $taxval,
  );
  $products = new WP_Query($product_args);
  ?

  ?php if ($products-have_posts()) : $i = 1; ? //and off into the loop.....

What I can't figure out is how to replace 'selecttaxonomy' with the output of the dropdown - help please. The page I'm working on is: https://ageingdj.com/0anotheredd-test/ (ignore the styling please)

Topic advanced-custom-fields dropdown custom-post-types Wordpress

Category Web


wp_dropdown_categories() will produce a select element with the default name and id of cat. You can change these by passing different values for id and cat in the $args array. The default value it uses is the term_id. Depending on what you're expected to use in the get_field() function, you can also change that in the $args array.

$args = array(
  'taxonomy'    => 'download_category',
  'order'       => 'ASC',
  'value_field' => 'slug',
);

Then in the second part:

$cat = esc_attr( $_GET[ 'cat' ] );
$product_args = array(
  'post_type'         => 'download',
  'posts_per_page'    => $per_page,
  'offset'            => $offset,
  'download_category' => $cat,
);

I've never combined ACF and EDD this way, so it might need some fiddling.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.