0

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)

0

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.

  • Hi there, Thanks for your answer but I'm getting the blank screen from hell! – Ageingdj Mar 15 '18 at 21:49
  • Sorry, pressed enter...What do I do on the second part please? Do I delete any rows? and shouldn't 'value_field' => 'slug', and 'download_category' => $cat, return the same value? – Ageingdj Mar 15 '18 at 21:53
  • Sorry, for some reason I now have results but not what I wat - i'm getting all my posts in reverse (latest first) not the EDD Downloads - wierd. – Ageingdj Mar 15 '18 at 22:04
  • Sorry, I just can't get this to work - anyone have any ideas please? I've also tried get_categories() but had no luck there either. (all I want is to pass the category selected from the drop down into $cat - thats all). – Ageingdj Mar 17 '18 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.