• I have this code working all time but, after updating to WordPress 4.2.1, this doesn’t work.

    // return just the missing replies in the comment table
    add_action( 'pre_get_comments', array( $this, 'return_missing_list' ) );
    public function return_missing_list( $comments = array() ) {
    
        // bail on anything not admin
        if ( ! is_admin() )
            return;
    
        // only run this on the comments table
        $current_screen = get_current_screen();
    
        if( 'edit-comments' !== $current_screen->base )
            return;
    
        // check for query param
        if ( ! isset( $_GET['missing_reply'] ) )
            return;
    
        // now run action to show missing
        $comments->query_vars['meta_key']   = '_cnrt_missing';
        $comments->query_vars['meta_value'] = '1';
        $comments->query_vars['date_query'] = array(
                    'after' => '10 months ago'
                );
    
        // Because at this point, the meta query has already been parsed,
        // we need to re-parse it to incorporate our changes
        $comments->meta_query->parse_query_vars( $comments->query_vars );
    } // end missing_reply_list

    Can you help me about please?

    Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Please try this.
    $comments->meta_query = new WP_Meta_Query();

    Before Doing
    $comments->meta_query->parse_query_vars( $comments->query_vars );

    Thread Starter Victor Campuzano

    (@vcgs)

    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?

    Thread Starter Victor Campuzano

    (@vcgs)

    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.

    Thread Starter Victor Campuzano

    (@vcgs)

    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_array which doesn’t break the cache but is not so ideal performance-wise. would be nice if pre_get_comments would 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_query hook instead.

    ok, it seems that’s where the query alteration belongs. it doesn’t make sense anymore to use pre_get_comments for this…

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘WordPress 4.2.1 pre_get_comments doesn't work after update’ is closed to new replies.