Skip to:
Content

bbPress.org

Ticket #3234: non_invasive_meta_query.diff

File non_invasive_meta_query.diff, 1.0 KB (added by morgul, 6 years ago)

Fix for this issue, making the query be non-invasive to non-bbPress queries

  • .php

    diff --git a/includes/forums/functions.php b/includes/forums/functions.mio.php
    index 692ef51..3841446 100644
    old new function bbp_pre_get_posts_normalize_forum_visibility( $posts_query = null ) { 
    18501850                // Get any existing meta queries
    18511851                $meta_query   = (array) $posts_query->get( 'meta_query', array() );
    18521852
     1853                // Don't add our meta query if we would mess up the existing query, as we shouldn't impose the presence of _bbp_forum_id meta key on the posts, for queries that aren't our own
     1854                if ( array_key_exists( 'relation', $meta_query ) && $meta_query['relation'] != 'OR' )
     1855                        return;
     1856
     1857                // Add this condition to not mess up with non-bbPress queries, making the presence of _bbp_forum_id meta key on the posts be optional
     1858                $meta_query['relation'] = 'OR';
     1859                $meta_query[] = array(
     1860                        'key' => '_bbp_forum_id',
     1861                        'compare' => 'NOT EXISTS',
     1862                        'value' => '',
     1863                );
     1864
    18531865                // Add our meta query to existing
    18541866                $meta_query[] = $forum_ids;
    18551867