Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › File Search Taxonomy Filter Not Working › Reply To: File Search Taxonomy Filter Not Working
Hi 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;
}