WordPress 4.2.1 pre_get_comments doesn't work after update
-
Please try this.
$comments->meta_query = new WP_Meta_Query();Before Doing
$comments->meta_query->parse_query_vars( $comments->query_vars );Thanks Navnell.
I don’t know why, but it applies the date filter but not the meta_key = meta_value .
New syntax about meta queries?
Any ideas?
Why it applies the “date” filter but nothing about the meta_key & meta_value statement?.
Thanks!
Sorry I don’t have much information.
I solved it using another type of code.
add_filter('comments_clauses', array($this, 'return_missing_list') , 10, 2); public function return_missing_list(array $pieces, WP_Comment_Query $query) { if (! is_admin()) { return $pieces; } // Esta función sólo se puede ejecutar si es admin $current_screen = get_current_screen(); // bail on anything not admin if ( is_admin() && ('edit-comments' == $current_screen->base) && (isset($_GET['missing_reply']))) { global $wpdb; $pieces['join'] = " INNER JOIN wp_commentmeta ON ( wp_comments.comment_ID = wp_commentmeta.comment_id )"; $pieces['where'] = "(comment_approved = '1') AND (comment_date >= DATE_SUB(NOW(), INTERVAL 1 MONTH)) AND (wp_commentmeta.meta_key = '_cnrt_missing') AND comment_type != 'pingback' AND comment_type != 'trackback'"; } return $pieces; }Hope you find it useful.
thanks! but altering the clauses may actually be a bad idea because it breaks caching. it doesn’t matter in your case but on frontend the comments query is cached using a unique key based on the query string. if you dynamically alter the clauses and use a persistant cache it returns the same cache for the same query string and possibly different clauses.
i ended up using the
comments_arraywhich doesn’t break the cache but is not so ideal performance-wise. would be nice ifpre_get_commentswould work again as expected…I’ve opened a ticket for this.
and already fixed. thanks!
Thank Boone, not me 🙂
for opening the ticket, i was to lazy…
No worries – it was messing in fairly critical ways with one of my plugins so I had to. FWIW, since 4.2.1 (and in the meantime) you can switch to using the
parse_comment_queryhook instead.ok, it seems that’s where the query alteration belongs. it doesn’t make sense anymore to use
pre_get_commentsfor this…
The topic ‘WordPress 4.2.1 pre_get_comments doesn't work after update’ is closed to new replies.
(@vcgs)
11 years, 1 month ago
I have this code working all time but, after updating to WordPress 4.2.1, this doesn’t work.
Can you help me about please?
Thanks!