Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Search results content
- This topic has 34 replies, 2 voices, and was last updated 1 year, 2 months ago by
erika.
-
AuthorPosts
-
February 26, 2025 at 2:00 pm #53110
erika
ParticipantHi there
I have pdfs that I am indexing. Please let me know how search excerpts can be shown from pdfs with a matching keyword and with a clickable link to the pdf which is in our woocommerce show.For example. Search for “adoption”. Results:
Issue #1. With adoption is is recommended that children be treated with the utmost confidentiality…
Issue #99. In homes where adoption is a …
Issue #400. Adoption is a common practice in the UK … etcMaybe you can point me to a tutorial or do it for me please? Admin access provided.
regards
ErikFebruary 26, 2025 at 3:35 pm #53111Ernest Marcinko
KeymasterHi Erik,
I recommend watching the video on this page about file search.
PDFs however can’t be displayed in a WooCommerce products widget – Elementor does not allow that, nor any other widget either. I guess that’s what you are trying to do, but Elementor will automatically remove them as the products widgets should only every display products and nothing else (and media files are not products).
The video tutorial on the link above will explain everything about searching files and file contents 🙂
February 27, 2025 at 2:41 pm #53123erika
ParticipantGreat, thank you! Works well…and yes, I want to list the products that come up from the search. If I add the pdfs as products, is it not possible to search products and not attachments in the same way? At the moment, the pdfs are listed with the context and if you click it goes directly to the pdf and not the “add to cart” page.
February 28, 2025 at 9:40 am #53131Ernest Marcinko
KeymasterIf you are using the elementor products widget, then for that you have to select the products to search and not the PDFs.
If you use the plugins onwn results container (similarly as it is in the tutorial and demo), then there is a chance. If the PDFs were uploaded to the products as attachments, then by changing this option WordPress will return the parent URL, which should be the product. Therefore the plugin will display the PDFs as results, but link to the product page itself.
March 3, 2025 at 10:40 am #53168erika
ParticipantThanks. No, I can choose to use the elementor widgit or not. We are still in the testing phase so there is flexibility. I will upload the PDF as an attachment as you suggest. I assume then I choose product and not attachment for “Post types to index”?
March 3, 2025 at 11:32 am #53169Ernest Marcinko
KeymasterI assume then I choose product and not attachment for “Post types to index”?
Yes – exactly.March 3, 2025 at 2:48 pm #53172erika
ParticipantThanks Ernest. I notice that when I choose product and not attachment, then the option to use the External File indexing feature goes away. But I do want to index those for the pdfs that are attached to the product…and to display the excerpt.
March 4, 2025 at 5:00 pm #53177Ernest Marcinko
KeymasterYou are welcome!
I don’t think there is a way to do that via settings I’m afraid. Products are not actually the files, they are two separate entities. There might be some hacky way to get around it, but I’m not sure.
Can you add temporary SFTP access, I might have to test some customized code to see if there is any way to do this.
March 4, 2025 at 6:12 pm #53179erika
ParticipantThanks for the response. You can try log in using the credentials I posted when I created this ticket. There is a File Manager plugin that will give you access to the files. However, this is our live site so…do you think your code will break anything?
March 5, 2025 at 8:29 am #53186Ernest Marcinko
KeymasterIt could happen, yes – as I don’t have a ready made code to test, this needs to be experimented with. With SFTP access I can correct any mistake immediately, while the file manager will not work if I make any mistakes. It would be much safer to use direct access.
Do you have a test or staging environment by any chance? I would much rather do index code experiments on a non-live site.
March 6, 2025 at 5:27 pm #53207erika
ParticipantYou cannot access this content.
March 6, 2025 at 5:29 pm #53208erika
Participantyou can also just paste you public key here
March 7, 2025 at 10:25 am #53214Ernest Marcinko
KeymasterYou cannot access this content.
March 7, 2025 at 3:16 pm #53220erika
ParticipantYou public key has been added, please try now
March 10, 2025 at 11:43 am #53240Ernest Marcinko
KeymasterThank you very much! I have tried, but I get a refused key message: https://i.imgur.com/pwZs7Fe.png
However, I didn’t need the SFTP access after all, I was able to create and test a custom code snippet that fetches the PDF attachments from the products and indexes them with the products as well. I have applied the custom code to the functions.php file in your theme directory.
The way it works is, that you can set up a widget to search for products. If there are any PDFs attached to the product, the code will check and will try to find it in the media library. If it’s in the media library, then it will index it’s contents with the product contents. Therefore searching parts from the PDF contents will return the product as the results as well. Just make sure that he attached PDF exists in the Media library as well.
The code that I applied below, for archive purposes:
function asp_get_file_id_from_url($file_url) { $file_path = ltrim(str_replace(wp_upload_dir()['baseurl'], '', $file_url), '/'); global $wpdb; $statement = $wpdb->prepare("SELECT <code>ID</code> FROM <code>wp_posts</code> WHERE guid='%s';", $file_url, $file_path); $attachment = $wpdb->get_col($statement); if (count($attachment) < 1) { return ''; } return $attachment[0]; } add_filter( 'asp_post_content_before_tokenize', function ( $content, $post ) { if ( $post->post_type !== 'product' ) { return $content; } $product = wc_get_product( $post->ID ); if ( $product->is_downloadable() ) { // Loop through WC_Product_Download objects foreach ( $product->get_downloads() as $key_download_id => $download ) { $download_link = $download->get_file(); // File Url $id = asp_get_file_id_from_url($download_link); var_dump($id, $download_link); if ( $id !== '' ) { $field_value = get_post_meta( $id, '_asp_attachment_text', true ); if ( $field_value !== '' ) { $content .= ' ' . $field_value; } } } } return $content; }, 10, 2 ); -
AuthorPosts
- You must be logged in to reply to this topic.