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

Index specific directory with attachments

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Index specific directory with attachments

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #53610
    erikaerika
    Participant

    Hi again Ernest

    Since our last contact we have been adding products and pdf attachments to woocommerce, it works great. However, we have other pdfs on our site that are also being indexed. Is it possible to add code to only index pdfs from a given directory or only index pdfs attached to a product?

    Thank you.

    #53623
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi Erika,

    Well, it might be possible with a custom code snippet, but I’m not a 100% sure. In the code below, change the $folder variable to the folder name where of where you want the attachments to be indexed from:

    add_filter(
    	'asp_index_post',
    	function ( WP_Post $post ) {
    		$folder = 'included_folder_name'; // Change this to the attachment folder to include
    		
    		if ( $post->post_type !== 'attachment' ) {
    			return $post;
    		}
    		if ( strpos($post->guid, $folder) !== false ) {
    			return $post;
    		}
    		return null;
    	}
    );

    After adding this code, please make a new index.

    Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    #53625
    erikaerika
    Participant

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

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

    #53701
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Great!

    You can set those here: https://i.imgur.com/4HHTe9I.png

    I hope this helps!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.