Check for taxonomy archive results on search.php page

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Check for taxonomy archive results on search.php page

This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 years, 11 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #27221
    FrisOnline76
    FrisOnline76
    Participant

    Hi,

    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 3 years, 11 months ago by FrisOnline76 FrisOnline76.
    #27222
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi 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).

    Best,
    Ernest Marcinko

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


    #27224
    FrisOnline76
    FrisOnline76
    Participant

    Hi 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,
    Niels

    #27225
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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')

    Best,
    Ernest Marcinko

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


    #27226
    FrisOnline76
    FrisOnline76
    Participant

    Thanks again Ernest! Issue solved 🙂

    #27229
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.