Restrict Index Table based Search to search only in PDFs in Working Papers

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Restrict Index Table based Search to search only in PDFs in Working Papers

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 years, 10 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #33564
    Bochumer57
    Bochumer57
    Participant

    We have four CPTs: JWE-Issues, JWE-Articles, JWE-Reviews and Working Papers. Some of them with PDFs attached. All 265 Working Papers have one PDF each. I built the Index Table and a search in Working Papers to search ONLY! in the PDF content. It is working but the results are showing PDFs from other CPTs too. I tried a lot of different settings but i am not able to restrict the search to search only in the content of the Working Paper PDFs.

    In general: Is that posibble and of so, where do i find the correct setting?

    Thanks in advance. I tried a lot of different search plugins. Yours is by far the very best.

    Link to the page:
    https://wine-economics.org/working-paper-test/

    #33583
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Thank you very much for your kind words!

    Unfortunately this is not possible I’m afraid. I can try suggesting a custom coded solution, but it may not work in all cases, or at all.

    add_filter('asp_results', 'asp_remove_attachments_by_cpt', 10, 1);
    function asp_remove_attachments_by_cpt($results) {
    	foreach ( $results as $k => &$r ) {
    		if ( $r->content_type == 'attachment' ) {
    			$p = get_post(wp_get_post_parent_id($r->id));
    			if ( $p->post_type != 'working_paper' ) {
    				unset($results[$k]);
    			}
    		}
    	}
    	return results;
    }

    Try adding this code 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.

    Best,
    Ernest Marcinko

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


    #33623
    Bochumer57
    Bochumer57
    Participant

    Hello Ernest

    Thank you for your response.
    The codeyou provided doesn’t work.
    I will try to find other setting.

    Cheers

    Ralf

    #33636
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    All right, I am not sure why it does not work though.

    Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.