• Hy there,

    I have a pagination in a page of my website and its working pretty good until I apply a filter.

    I have a page where I have listings and filters to filter the listings.

    Only 12 listings are showing per page.

    If a filter is applied then it removes the filters applied and redirect me to second page of listings without filters applied.

    eg: domain.com/inventory/page/2

    But what I want is if a filter is applied and user clicked on next page arrow it should redirect to next page with the filter applied.

    eg: domain.com/inventory/page/2/?filter[]=true

    Any idea how i can do this by PHP?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator t-p

    (@t-p)

    I recommend asking at your theme’s dedicated support. They may have an easy, supported solution.

    Moderator bcworkz

    (@bcworkz)

    If there’s no easy theme solution, you could search for a plugin that provides for filtering, or you could develop your own solution.

    Restricting a posts query with filter criteria is best done through the “pre_get_posts” action. Pagination works better this way. Your action callback would check for the “filter[]” query var and if it exists modify the query accordingly. Often “tax_query” or “meta_query” args will be involved.

    It’s generally preferable to whitelist your query var through the “query_vars” filter. Just add your query vars to the passed array and return it. They will then show up in WP_Query’s query_vars array. If you don’t do this, you need to get the URL’s query values from $_GET

    The other piece of the puzzle is to have the pagination URLs include the current filtering criteria in its URLs. How to do so depends on the pagination functions being used. There is usually a filter hook with most pagination functions through which URL query strings can be added.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to fix the pagination issue?’ is closed to new replies.