craigbailey

Forum Replies Created

Viewing 1 post (of 1 total)
in reply to: Exclude download files from WordPress search results #31476

craigbailey
Member

Thanks Shaon,

The change to wpdm-functions.php gave me half the result I was after – it blocked people from downloading the files from the public pages.
But it was still showing them as listing the search results (and then clicking on the link would give an error).

In the end I was able to fix it by excluding the post type from search results.
The following code when placed in functions.php (ie in a child theme or theme folder) will exclude them from search results. Adding it here in case it is of use to anyone else in the future.

add_action( ‘init’, ‘exclude_wpdmpro_type’, 50 );

/*
* exclude downloads from search results
*/
function exclude_wpdmpro_type() {
global $wp_post_types;

if ( post_type_exists( ‘wpdmpro’ ) ) {

// exclude from search results
$wp_post_types[‘wpdmpro’]->exclude_from_search = true;
}
}

Viewing 1 post (of 1 total)