Skip to:
Content

bbPress.org

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#2471 closed defect (bug) (fixed)

bbp_exclude_forum_ids function bugging custom WP_Query

Reported by: unsalkorkmaz Owned by: johnjamesjacoby
Priority: high Milestone: 2.6
Component: Component - Forums Version: 2.4.1
Severity: normal Keywords: needs-testing needs-patch
Cc: nashwan.doaqan@…

Description

How to re-produce:
1) Create 1 normal forum and 1 private forum
2) Open a topic in normal forum and post a reply
3) Create a custom function that using a WP_Query in reply content.
You will see bbPress adds extra meta_query in your WP_Query and basically its corrupting your query for everyone except keymasters like this:

    [meta_query] => WP_Meta_Query Object
        (
            [queries] => Array
                (
                    [0] => Array
                        (
                            [key] => _bbp_forum_id
                            [value] => 1031
                            [type] => numeric
                            [compare] => !=
                        )

                )

            [relation] => AND
        )

Is this working as intended? If it is, can you give me a solution for this?

Change History (8)

#1 @unsalkorkmaz
13 years ago

my temporary solution is:

remove_action( 'pre_get_posts', 'bbp_pre_get_posts_normalize_forum_visibility', 4 );

wp_query run

add_action( 'pre_get_posts', 'bbp_pre_get_posts_normalize_forum_visibility', 4 );

#2 @johnjamesjacoby
13 years ago

Can you include an example of the new WP_Query you're calling in your custom function?

#3 @unsalkorkmaz
13 years ago

My query is:

new WP_Query(array(
		'post_type' => apply_filters( 'firmasite_pre_get_posts_ekle', array( 'post', 'page' )),
		'post__in' => $posts,
		'posts_per_page' => -1,
		'ignore_sticky_posts' => 1,
		'orderby' => 'post__in',
	));

Its a part of function that helps users to link other contents in replies or topic like this:
​http://theme.firmasite.com/support/topic/im-lost/page/2/#post-1443

(Btw, I can send you my theme so you can test it if you want. You can easily add content blocks to topics, replies in bbpress like this: ​http://base.theme.firmasite.com/forums/topic/example-topic/ )

#4 @johnjamesjacoby
13 years ago

  • Component General → Forums
  • Keywords needs-testing needs-patch added
  • Milestone Awaiting Review → 2.5

Thanks. I'll take a look in the next few days.

Moving to 2.5 to investigate.

#5 @johnjamesjacoby
13 years ago

  • Milestone 2.5 → 2.6

I'm not able to duplicate this on the latest trunk.

Moving this to 2.6 so we can investigate after 2.5 is released.

#6 @unsalkorkmaz
13 years ago

@JJJ,
I found it. Here try this:

1) Create 1 private forum
2) Add this code to functions.php or in a plugin/mu-plugin:

  add_action('after_setup_theme', "firmasite_example_query" );
  function firmasite_example_query() {

	$testing = new WP_Query( array( 
		'post_type' => array( 'post', 'page', 'topic' ), 
		'showposts' => 9,
		'ignore_sticky_posts' => 1
	));
	print_r($testing);
	
  }

3) Check your site's any page (as someone except keymaster), you will see print of query which have this excluding for everyone except keymasters:

            [meta_query] => Array
                (
                    [0] => Array
                        (
                            [key] => _bbp_forum_id
                            [value] => 1701
                            [type] => numeric
                            [compare] => !=
                        )

                )

If you exclude topic post type from query, query will change and work but if you want to include topic post type in query, it gets corrupted and not works for other post types.

Last edited 13 years ago by unsalkorkmaz (previous) (diff)

#7 @alex-ye
13 years ago

  • Cc nashwan.doaqan@… added

#8 @johnjamesjacoby
13 years ago

  • Owner set to johnjamesjacoby
  • Resolution → fixed
  • Status new → closed

In 5312:
Use array_diff() rather than array_intersect() in bbp_pre_get_posts_normalize_forum_visibility() to allow custom post_type queries (that still include forums/topics/replies) to pass through without hidden/private forum meta_data assistance. Fixes #2471.

Last edited 13 years ago by johnjamesjacoby (previous) (diff)
Note: See TracTickets for help on using tickets.