Great, thanks!
[Solved] Exclude some PDF from results when using Download Monitor
-
When you're using the Download Monitor plugin (which is good for manage files in Wordpress), you can add some beautiful search capabilities by file content to it with the help of the WPFTS Pro plugin.
But the question is: is it possible to exclude some files from the search results? For example, some files are private or you just don't need for them to be searched.
The answer is YES and you can do that in at least two ways.
Both solutions require some PHP skills to add a couple of lines of code, but it's actually very simple.
Case 1: You want to exclude one or just some PDF files.
To follow this method, you can just add a rule to the wp_query that excludes a set of specific posts.
What you need to do exactly:-
Please open each of Download Monitor's posts that you want to exclude from the search results and record it's Post ID (usually it's written in the URL of the Edit Post page).
-
Add the small part of PHP code to your
functions.php
(in the root of your current theme):
add_action('pre_get_posts', function(&$wpq) { if ($wpq->is_search && $wpq->is_main_query()) { $wpq->set('post__not_in', array( 62324 )); // Here you need to list your IDs } });
All done! When you save modified
functions.php
code, the search should filter out these posts from the search results.P.S. This will work with ANY posts, not only Download Manager's posts or attachments. ANY posts. You even don't need to WP Fulltext Search plugin, because it's WP basic functionality.
Case 2: You want to exclude a lot of PDF files.
In case you want to exclude a big set of files from the search result, you need to create a special category in the Download Manager and assign all those posts to this category. And then add some PHP code to exclude all posts within this category from the search results.
- First of all, create the Download Monitor's Category and remember it's slug.
- Go to the Download Monitor file's list and place some of them to this new category.
- After it, add this code to your
functions.php
file.
add_action('pre_get_posts', function(&$wpq) { if ($wpq->is_search && $wpq->is_main_query()) { $wpq->set('tax_query', array( array( 'taxonomy' => 'dlm_download_category', 'field' => 'slug', // Here you need to put your category slug 'terms' => array( 'download-category-1' ), 'operator' => 'NOT IN', ), ), ); } });
And that's it. After saving the
functions.php
all posts within this category should magically drop out of search results!You can download this addon and modify it for your needs to leave the
functions.php
file intact.https://fulltextsearch.org/wpfts-addon-custom-filter-dm-category-1.0.1.zip
Hope this helps.
-