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 11 months, 3 weeks ago.
- AuthorPosts
- August 18, 2023 at 12:59 am #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
August 18, 2023 at 3:14 pm #45117Hi,
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.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
September 15, 2023 at 1:21 am #45386Thanks Ernest, will try that out and let you know
- AuthorPosts
You must be logged in to reply to this topic.