0

I'm having an issue with a custom search form that doesn't filter results as I need it to. I need it to filter based on the date and/or category(s) selected.

code used within template:

<aside class="widget widget_filter">
      <h4>FILTER SEARCH</h4>
      <form method="get" action="<?php bloginfo('url'); ?>">

      <input type="hidden" name="post_type" value="news" />

      <?php $args = array(
        'order' => 'DESC',
        'orderby' => 'date',
        'post_type' => 'news',
        'posts_per_page' => '-1'
      );

      $counter = 0;
      $ref_month = '';
      $monthly = new WP_Query($args);
      if( $monthly->have_posts() ) : ?>
        <p>Date</p>
        <select name="m">
        <option value="">Please Select Date</option>

        <?php while( $monthly->have_posts() ) : $monthly->the_post();

          if( get_the_date('mY') != $ref_month ) : ?>

            <option value="<?php the_date('Ym'); ?>"><?php echo get_the_date('F Y'); ?></option>
            <?php $ref_month = get_the_date('mY');
            $counter = 0;
          endif;
        endwhile; ?>

        </select>
      <?php endif; ?>
      <?php wp_reset_postdata(); ?>
      <p>Filed In</p>
      <?php $terms = get_terms( 'news-category' ); 
      foreach( $terms as $term ) : ?>
        <label><input type="checkbox" name="cat" value="<?php echo $term->term_taxonomy_id ?>" /><?php echo $term->name; ?></label>
      <?php endforeach; ?>

      <input type="image" src="<?php echo get_stylesheet_directory_uri(); ?>/images/btn-filter.png" />
      </form>
    </aside>

If I select a date only it works fine and redirects to a url similar to website.dev/2013/09/?post_type=news&x=67&y=8

If I select a date and category it redirects to a 404 page with a url similar to website.dev/?post_type=news&m=&cat=7&x=88&y=21

I've tried changing the cat parameter to category and Wordpress ignores it. My .htaccess file is setup as Wordpress recommends and I've flushed DNS via the permalinks page in case that was an issue but this didn't resolve it.

How can I get it to filter by both parameters?

edit: Could it be due to it being a custom post type and custom taxonomy? I couldn't find what the correct parameter name would be to pass instead of 'cat'

2

You are likely getting unexpected results due to your query string. I would recommend getting familiar with the following:

Reserved Terms

Avoiding the following reserved terms is particularly important if you are passing the term through the $_GET or $_POST array. Doing so can cause WordPress to respond with a 404 error without any other hint or explanation.

Click the link for WordPress Reserved Terms to see the complete list of terms.

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.