This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 27 total)
  • Author
    Posts
  • in reply to: Index specific directory with attachments #53696
    erikaerika
    Participant

    Thanks 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.

    in reply to: Index specific directory with attachments #53625
    erikaerika
    Participant

    Thank you! I’ll try it out and let you know.

    in reply to: Search results content #53333
    erikaerika
    Participant

    great, will do.

    in reply to: Search results content #53314
    erikaerika
    Participant

    Thank 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?

    in reply to: Search results content #53301
    erikaerika
    Participant

    You cannot access this content.

    in reply to: Search results content #53298
    erikaerika
    Participant

    Thanks 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…

    in reply to: Search results content #53293
    erikaerika
    Participant

    You cannot access this content.

    in reply to: Search results content #53290
    erikaerika
    Participant

    Hi 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
    );
    • This reply was modified 1 year, 2 months ago by erika.
    in reply to: Search results content #53273
    erikaerika
    Participant

    The content has definitely been added to the attachment details, attached.

    in reply to: Search results content #53270
    erikaerika
    Participant

    i turned off “Return media files as results”, as attached. So nearly there. Now just for the excerpts to appear in the search results for the product with the attached pdf. By excerpt I mean indexed content/description.

    • This reply was modified 1 year, 2 months ago by erika.
    in reply to: Search results content #53269
    erikaerika
    Participant

    https://realacademy.net/the-knowing-field/ test with “Hutus”

    • This reply was modified 1 year, 2 months ago by erika.
    in reply to: Search results content #53267
    erikaerika
    Participant

    I 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.

    in reply to: Search results content #53264
    erikaerika
    Participant

    Thanks 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?

    in reply to: Search results content #53243
    erikaerika
    Participant

    Thanks 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”.

    • This reply was modified 1 year, 2 months ago by erika.
    in reply to: Search results content #53242
    erikaerika
    Participant

    Thank 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.

Viewing 15 posts - 1 through 15 (of 27 total)