Attachment – Links Results to Attachment Page issue

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Attachment – Links Results to Attachment Page issue

This topic contains 9 replies, has 2 voices, and was last updated by

 
Keymaster
2 years, 11 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #21239

    Participant

    Hi!,

    Purchased Ajax Search Pro yesterday and I have been working through its features – I am impressed and overall happy with it thus far! I have a photography site and when a user searches and finds an Attachment, I want them to be able to click the results thumbnail and ideally view the image in a lightbox. I have read through the forums and I see that may be an issue. So the next approach that I am trying to have work is to at least display the selected result image on images “attachment page”. Unfortunately when I select this option in the Attachments menu “Link results to: attachment page” the site sill always opens up the direct file url. For example it opens: “https://photography.toddplunkett.com/wp-content/uploads/2019/02/DSC09388.jpg” instead of the attachment page for that image. Am I missing a configuration setting somewhere that is causing this to happen?

    On the lightbox topic, I use the justified image grid plugin and it has significant flexibility in how it can receive post and image IDs and custom urls to open an image in one of its lightbox options. I am betting there is a way to make this happen. I wonder if you have explored it at all. It works very well – if I could figure out how to pass a Post ID from a search result, it can open it in a lightbox.

    Thank You for your help!

    #21250

    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!

    Best,
    Ernest Marcinko

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


    #21257

    Participant

    Ernest – Thank you for your very prompt reply – fantastic customer service. I will test this out today and report back my findings.

    #21262

    Participant
    You cannot access this content.
    #21264

    Hi,

    The dev tools does not help in this case, as the correction is a server side script. If you want, you can add temporary FTP details, and I will try debugging the code directly. That internal function should return the attachment page url, unless there is a 3rd party filter applied to it. I might be able to tell, via debugging that code section.

    The second code should go to the functions.php file in your theme/child theme directory. Sorry about that, I forgot to mention. It does nothing though, it’s just a sample on how to get the ID and the links. The post_id and the url variables in the script contain the attachment ID and the image URL. So if the lightbox script has an API, you can use that there, with those variables.

    Best,
    Ernest Marcinko

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


    #21265

    Participant
    You cannot access this content.
    #21273

    Participant
    You cannot access this content.
    #21282
    You cannot access this content. Best,
    Ernest Marcinko

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


    #21286

    Participant

    For anyone who runs into this issue, I wanted to let you know the problem seems to have been caused by the Yoast SEO plugin conflicting. I disabled it and all works fine. (For now I have implemented the The SEO Framework plugin without conflict)

    Thanks Again to Ernest for his assistance and very prompt support response!

    #21291
    You cannot access this content. Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.