Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Check for taxonomy archive results on search.php page
- This topic has 5 replies, 2 voices, and was last updated 6 years ago by
Ernest Marcinko.
-
AuthorPosts
-
May 11, 2020 at 12:15 pm #27221
FrisOnline76
ParticipantHi,
Not really sure if this question is related to the plugin but I’m looking for a way / conditional statement to check if a search result is a taxonomy archive link.
It seems like there isn’t such a conditional statement within WordPress Core as
is_tax()only checks if the current page is a taxonomy archive page. This might be related to the issue that taxonomy archive pages can’t be searched / shown as result with the default WordPress search.I’ve searched the Ajax Search Pro documentation but didn’t find the answer there. I found the asp_query_args filter but that filter changes the query and is not related to they way results are shown.
It there any way to check if a search result is a taxonomy archive page on the search results page (search.php)?
Kind regards,
Niels Pilon-
This topic was modified 6 years ago by
FrisOnline76.
May 11, 2020 at 12:21 pm #27222Ernest Marcinko
KeymasterHi Niels,
Well, you cannot check that via WordPress core functions, as all of those items there are “mimiced” as post types, since the results page is built for that.
There might be a way though, via using the get_asp_result_field() function in there. Try:
if ( get_asp_result_field('content_type') == 'term' ) {The “content_type” field should contain the result type – in this case you are looking for “term”, that represents taxonomy terms (taxonomy archive links).
May 11, 2020 at 12:28 pm #27224FrisOnline76
ParticipantHi Ernest,
Thanks for your quick reply which solved the issue!
Can the function also be changed to check for a specific taxonomy term as it looks like it will be used for all terms…?
Kind regards,
NielsMay 11, 2020 at 12:46 pm #27225Ernest Marcinko
KeymasterHi,
Well, it should return the taxonomy, if defined:
get_asp_result_field('taxonomy')..as well as the term ID, if needed:
get_asp_result_field('id')May 11, 2020 at 12:53 pm #27226FrisOnline76
ParticipantThanks again Ernest! Issue solved 🙂
May 11, 2020 at 1:52 pm #27229Ernest Marcinko
KeymasterYou cannot access this content.
-
This topic was modified 6 years ago by
-
AuthorPosts
- You must be logged in to reply to this topic.