Preset filters without using URL

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Preset filters without using URL

This topic contains 2 replies, has 2 voices, and was last updated by seamusashley seamusashley 9 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #45104

    Hey team!

    My site is for an art gallery. I have all the exhibitions as a CPT, and the artists as a CPT. For the exhibitions, the artists are set using the category taxonomy.

    On each artist page (single-artist.php) I would like to use ASP to load in the exhibitions with a preset filter showing only work from that artist. I am aware you can do this via the URL, but that would give me long urls where I want short clean ones. So is it possible to somehow set this preset in the PHP/JS somehow?

    Also – If we did this – would the page still hold good SEO?

    Let me know, thanks

    • This topic was modified 10 months, 1 week ago by seamusashley .
    Ernest Marcinko
    Ernest Marcinko


    Sure! It is possible to do programmatically via the Frontend Filters API.

    It highly depends on the exact scenario, but this is the starter code you are looking for:

    add_filter('asp_pre_get_front_filters', 'asp_change_a_filter', 10, 2);
    function asp_change_a_filter($filters, $type) {
      if ($type == 'taxonomy') {
    	$selected = array(
    		// page id => selected category ID,
    		1 => 123,
    		2 => 12344
        foreach ($filters as $k => &$filter) {
    		// Go through the filter items via a loop
    		foreach ($filter->get() as $kk => $item) {
    		  // Should this be selected?
    		  if ( isset($selected[get_the_ID()]) &&  $item->id == $selected[get_the_ID()] ) {
    			  $filter->attr($kk, 'selected', true, true);
    		  } else {
    			  // Unselect the rest
    			  $filter->attr($kk, 'selected', false, true);
      return $filters;

    Unfortunately I could not test this right now, but should be very close to a possible solution.

    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    Thanks Ernest, will try that out and let you know

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.