Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › File Search Taxonomy Filter Not Working
- This topic has 1 reply, 2 voices, and was last updated 3 years ago by
Ernest Marcinko.
-
AuthorPosts
-
May 24, 2023 at 2:26 am #42690
benjaminjohnjamieson
ParticipantI am trying to create a searchable PDF database with two taxonomy filters. I have tried two different approaches for this:
1. Use this plugin to search through a custom post type with a PDF attached to each post. The search has two filters for category and tag. This works correctly, but I can’t find any way for the search results to link directly to the attached PDF instead of the the post’s permalink.
2. Use this plugin to search media files of the type PDF and filter using two custom taxonomies specific to media files. The issue here is that the front end filters do not work at all. I get all keyword matches for any uploaded PDF files no matter which taxonomy filter I have applied. The filter does not eliminate files that do not have any given taxonomy.
Is there something I can do to make this work with either approach?’
Thank you,
Ben JamiesonMay 24, 2023 at 1:58 pm #42718Ernest Marcinko
KeymasterHi Ben,
The main issue with the setup is, that the media files are not actually categorized – only the parent posts.
However there is still something we can try to make it work. Setup 1. is the way to go, that will actually filter the posts. Please use that in combination with the custom code below. The code will fetch the attached file and change the post permalink to the file URL in the results list.Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_filter( 'asp_results', 'asp_change_permalink_to_media', 10, 1 ); function asp_change_permalink_to_media( $results ) { foreach ($results as $k=>$r) { if ( isset($r->post_type) ) { $files = get_attached_media( 'application/pdf', $r->id ); if ( isset($files[0], $files[0]->ID) ) { $r->link = wp_get_attachment_url( $files[0]->ID ); } } } return $results; } -
AuthorPosts
- You must be logged in to reply to this topic.