Exclude media from front search
- dnikolaParticipant4 years, 6 months ago #19149
Hello Partice,
here is my current settings on data 2.2 page https://prntscr.com/ro2rxg
How I can change a option to “Index all status. To replace search in admin too. Only published is shown in front search.” but I don’t want to show them on front.
I want to index them and on wp admin to replace query’s on media page.wpsolrKeymaster4 years, 6 months ago #19157There is a protection in WPSOLR that prevents to show on front-end any post type defined as ‘exclude_from_search’ => true. For instance WooCommerce orders will never be shown on front-end, even if selected in 2.2 to be indexed for search admin.
If medias are not excluded from search, they will show up in WPSOLR front-end search results.
dnikolaParticipant4 years, 6 months ago #19423I made few test and come back to report but now i see that you edited your first answare.
Ok with wp solr I am still getting images showing up
I am using this code// Exclude images from search results – WordPress
function onlyposts_filter_wp_search($query) {
//Filter Search only in the front-end and not in the Admin.
if (!$query->is_admin && $query->is_search) {
//Search in Posts only. Excludes Pages, Attachments and CPTs.
$query->set(‘post_type’, ‘post’);
}
return $query;
}
add_filter(‘pre_get_posts’,’onlyposts_filter_wp_search’);but without wpsolr only posts show up.
What did you want to tell with this get_post_types( [‘exclude_from_search’ => false] ) ) ?dnikolaParticipant4 years, 6 months ago #19424Ok,
figured out
this helped.
add_action( ‘init’, ‘exclude_from_search’ );
function exclude_from_search() {
global $wp_post_types;
/* Exclude ‘page’ post type. */
$wp_post_types[‘page’]->exclude_from_search = true;
/* Exclude ‘attachment’ post type. */
$wp_post_types[‘attachment’]->exclude_from_search = true;
}but you could have this as option in plugin settings ..
You must be logged in to reply to this topic.