Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Attachment – Links Results to Attachment Page issue › Reply To: Attachment – Links Results to Attachment Page issue
Hi,
Thank you very much for your kind words!
I just tested that feature, but it seems to be working okay on my end. The ‘attachment page’ is basically the attachment parent, that is the relation to the page where the attachment was uploaded to. I’m guessing that maybe an internal WordPress option also affects that, I am not sure.
Anyways, I think I might know how to bypass that. If you want to test this fix, then please follow these steps:
1. Make sure to have a full site back-up just in case 🙂
2. Open up the wp-content/plugins/ajax-search-pro/includes/classes/search/class-asp-search-attachments.php file on your server via FTP
3. Replace it’s contents with this
4. Save the file, and it’s done
Hopefully, that should force the correct attachment page URL.
As for the post ID, it is possible to get it when clicking on the result, via a custom script. I have made a script sample for you, that may help you with that:
add_action('wp_footer', 'asp_add_custom_js', 99);
function asp_add_custom_js() {
?>
<script>
jQuery(function($) {
$('.asp_r').on('click', '.item', function(e) {
// Is this an attachment result?
if ( $(this).hasClass('asp_r_attachment') ) {
// Prevent result redirection
e.preventDefault();
e.stopImmediatePropagation();
// use the post_id and url variables as you like
var post_id = $(this).attr('class').match(/asp_r_attachment_(.*?) /)[1];
var url = $(this).find('a.asp_res_url').attr('href');
}
});
});
</script>
<?php
}
I hope this helps!