Thread Starter
Hal
(@halburgissnet)
I found the cause but now have a question too. So our client wanted to make sure attachments did not show in the search results. So we now have this filter which seems to have worked, or at least not caused any php isues (and it is now causing the php Warning about call_user_func):
add_filter( 'relevanssi_indexing_restriction', function ( $restriction ) {
global $wpdb;
$restriction .= " AND post.ID NOT IN (SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' ) ";
return $restriction;
});
In Settings under Indexing, “attachment” is not checked. But “Excluded from Search” says No. So, is there a better way to do this?
-
This reply was modified 2 years, 7 months ago by Hal.
The format of the filter has changed some time ago, that’s why it’s causing the error. See here for the filter hook instructions, but the function should be:
add_filter( 'relevanssi_indexing_restriction', function ( $restriction ) {
global $wpdb;
$restriction['mysql'] .= " AND post.ID NOT IN (SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' ) ";
$restriction['reason'] .= ' An attachment';
return $restriction;
});
However, there’s no reason to use a filter for this. Just uncheck attachment
in the post types to index list; that’s much easier. The “Excluded from search” value has nothing to do with the Relevanssi search, it just tells how the post type is defined when it was created.
Thread Starter
Hal
(@halburgissnet)
Ah! Thank you! I was hoping that was the case. And thank for excellent support and very nice plugin too!