Forum Replies Created
-
AuthorPosts
-
erika
ParticipantThanks Ernest, this code works well! I am only indexing the pdfs I need. By the way, where can I find the search suggestion tutorial? The keywords that are listed below the search textbox.
erika
ParticipantThank you! I’ll try it out and let you know.
erika
Participantgreat, will do.
erika
ParticipantThank you, it is working. I very much appreciate the extra support!! This will help us very much.
Will you integrate this code into future versions of the plugin or do I need to update functions.php with the code if I do a restore on my side?
erika
ParticipantYou cannot access this content.
erika
ParticipantThanks Ernest, by context I mean the same as what appears in the results with a search against a pdf. With the new code there is an error in the dropdown, please see attached. You are welcome to try ftp in. the code is under /data/realacademy…
erika
ParticipantYou cannot access this content.
erika
ParticipantHi Ernest, the code below is what’s in my production functions.php. It is not returning the text/content for the search results unfortunately – I did a recreate index. See attached.
add_filter( 'asp_results', 'asp_get_attachment_to_product_content', 10, 4 ); function asp_get_attachment_to_product_content( $results, $search_id, $is_ajax, $args ) { // --- DO NOT CHANGE ANYTHING BELOW --- foreach ( $results as $k =>&$r ) { if ( $r->post_type !== 'product' ) { continue; } $product = wc_get_product( $r->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); if ( $id !== '' ) { $field_value = get_post_meta( $id, '_asp_attachment_text', true ); if ( $field_value !== '' ) { $r->content = wd_substr_at_word($field_value, 130); break; } } } } } return $results; } 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 );erika
ParticipantThe content has definitely been added to the attachment details, attached.
erika
Participanterika
Participanthttps://realacademy.net/the-knowing-field/ test with “Hutus”
erika
ParticipantI am doing something wrong, see attached. The product is item 1 in the search result – however it has no excerpts (I did index with the remote server option). Item 2 in the search I assume is the pdf directly accessed (not through the product). I need the product only with the excerpt and not the pdf yet. The user needs to go to the product with add to cart – which is working correctly from the search result. Thanks Ernest, I appreciate the help very much.
erika
ParticipantThanks again Ernest! Do I need both settings as attached? As per your code, the pdf gets retrieved with the product – however, does it get sent to the remote server without the attachment option?
erika
ParticipantThanks Ernest! Appreciate it! I wrote a response earlier and I am not sure where it is. So, please see the attachment called search.jpg. The search for “Chernobyl” correctly returns the product item with the attached pdf and the attachment with the excerpt. How can I get the product item to return the excerpt in the pdf indexed content?
With the public key, I forgot to mention to use my name “erik”.
erika
ParticipantThank you so much Ernest, really appreciate this code! I think I may not be getting the config quite right with it. Sorry, i did not say the key is loaded under “erik” and not your name.
I set “Index table option” to “Products” only (not attachment) and I “create a new index”. Under my search for a keyword, the results return the pdf that contains that keyword but does not have the excerpts. I notice that the pdf under media does not have “Content (not editable)” like the directly indexed pdfs. Also, I cannot set the remote server when choosing “Products” only – unlike “Attachment” that has the remote server set up.
Should I choose “Attachment” as well? In fact, this message to you may be redundant. I have selected attachment as well and am currently reindexing. It takes awhile though so I wrote this message.
-
AuthorPosts