- This topic has 2 replies, 2 voices, and was last updated 1 year ago by seamusashley.
-
AuthorPosts
-
August 18, 2023 at 12:59 am #45104seamusashleyParticipant
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 #45117Ernest MarcinkoKeymasterHi,
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.
September 15, 2023 at 1:21 am #45386seamusashleyParticipantThanks Ernest, will try that out and let you know
-
AuthorPosts
- You must be logged in to reply to this topic.