Forums Forums Search & Filter Pro Filter Current Archive Category

Tagged: 

Viewing 10 posts - 1 through 10 (of 18 total)
  • Anonymous
    #190280

    Hello, I was wondering if it is possible that on an archive page of a site to have the filter only apply to the current category.

    For example if I am on page.com/category/filtered that on search that the filter would only filter those posts.

    This would be in the archive.php file in our build which would mean it would have to be agnostic to category number.

    Is it possible to have one filter that can be set in a function to grab the id of the current category and upon filter stay restricted to that category?

    Trevor
    #190333

    If you are using the Post Type Archive display results method, you can do as you want. On the General Settings tab you can select to Auto Detect the Category.

    On the Display Results tab, you can select to stay within the category pages.

    You also need to add the category to the form, but use custom CSS to hide that field.

    Anonymous
    #190362

    Hey Trevor, thank you for the reply! I will take a look into those settings. Thank you so much!

    Anonymous
    #190392

    Hey Trevor. I am looking at the general settings while using the Post Type Archive results method and do not see the auto detect category setting.

    Anonymous
    #190398

    Nevermind I see the setting.

    Trevor
    #190404

    Here (the third red box in this shot):

    https://www.screencast.com/t/Qi1FiS6F0S

    And here (the second red box):

    https://www.screencast.com/t/DoKL7OyeY

    Anonymous
    #190414

    So that is working as intended, but it seems our client wants to be able to direct users to pages that are archives of child categories. For example if we have a parent category that is Alerts and it has a child category of say emergency.

    If a user is linked to domain.com/category/emergency would those settings keep it restricted to emergency or upon search would it search the parent category as I am sure the auto detect would pick up the parent.

    Trevor
    #190418

    It should pick up the child, I think.

    Anonymous
    #190430
    function wpd_sort_by_meta( $query ) {
    
      $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
      $category = get_the_category();
    
      var_dump($category);
    
      if ( $query->is_archive() && $query->is_main_query() ) {
          $query->set( 'cat', $category );
          $query->set( 'meta_key', 'start_date' );
          $query->set( 'paged', $paged );
          $query->set( 'orderby', 'meta_value' );
          $query->set("search_filter_id", 18437);
      }
    }
    add_action( 'pre_get_posts', 'wpd_sort_by_meta' );

    That is my query that displays the initial results for the archive page which initially works. The issue is upon form submission the category changes so on initial load if I dump category or category[1] it will be a value of 4904 which is the id of the category but that changes upon form submission.

    Trevor
    #190450

    So, when the page loads OK first time, but any change doesn’t work, or does work but the URL does not change? Or maybe the page title is wrong?

Viewing 10 posts - 1 through 10 (of 18 total)