Plugin Author
Ajay
(@ajay)
Thanks for the quick response! Can you please give a code example of how I might override the match_fields from the theme level?
Plugin Author
Ajay
(@ajay)
function change_crp_match_fields( $match_fields ) {
global $wpdb;
// Are we matching only the title or the post content as well?
$match_fields = array(
"$wpdb->posts.post_content",
);
return $match_fields;
}
add_filter( 'crp_posts_match_fields', 'change_crp_match_fields' );
thanks for showing me how to use the filter. That is working for me! One thing to note for anyone else who may be doing this: when I added the above filter, I kept getting a DB error:
Can't find FULLTEXT index matching the column list
My query looked like this:
SELECT wp_posts.*, MATCH (wp_posts.post_content) AGAINST ('Can Dogs Eat Stri…') as score
FROM wp_posts
INNER JOIN wp_postmeta
ON ( wp_posts.ID = wp_postmeta.post_id )
WHERE 1=1
AND ( wp_posts.post_date <= '2023-02-17 02:32:43' )
AND wp_posts.ID NOT IN (642)
AND ( ( wp_postmeta.meta_key = 'cdet_safety_classification'
AND wp_postmeta.meta_value = 'safe' ) )
AND wp_posts.post_type = 'post'
AND ((wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'inherit'))
AND MATCH (wp_posts.post_content) AGAINST ('Can Dogs Eat Stri…')
GROUP BY wp_posts.ID
ORDER BY score DESC
LIMIT 0, 6
With some trial and error, I ended up running this sql and it fixed the error:
ALTER TABLE wp_posts ADD FULLTEXT crp_related_content(post_content);
The matching is working better for me now that I only match for the post_content. Thx again!
Plugin Author
Ajay
(@ajay)
Of course! I had removed this when I updated the plugin to use either the post title or both.