The comment_feed_join WordPress PHP filter allows you to modify the JOIN clause of the comments feed query before it’s executed.
Usage
add_filter('comment_feed_join', 'your_custom_function', 10, 2); function your_custom_function($cjoin, $query) { // your custom code here return $cjoin; }
Parameters
$cjoin
(string) – The JOIN clause of the query.$query
(WP_Query) – The WP_Query instance (passed by reference).
More information
See WordPress Developer Resources: comment_feed_join
Examples
Add a custom table to the JOIN clause
This example adds a custom table called wp_custom_table
to the JOIN clause.
add_filter('comment_feed_join', 'add_custom_table_to_join', 10, 2); function add_custom_table_to_join($cjoin, $query) { global $wpdb; $cjoin .= " LEFT JOIN {$wpdb->prefix}custom_table ON {$wpdb->prefix}custom_table.comment_ID = {$wpdb->prefix}comments.comment_ID"; return $cjoin; }
Join with postmeta table
This example joins the postmeta
table to filter comments by a specific post meta key and value.
add_filter('comment_feed_join', 'join_with_postmeta_table', 10, 2); function join_with_postmeta_table($cjoin, $query) { global $wpdb; $cjoin .= " INNER JOIN {$wpdb->prefix}postmeta ON {$wpdb->prefix}comments.comment_post_ID = {$wpdb->prefix}postmeta.post_id"; return $cjoin; }