Skip to:
Content

bbPress.org

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#2471 closed defect (bug) (fixed)

bbp_exclude_forum_ids function bugging custom WP_Query

Reported by: unsalkorkmaz's profile unsalkorkmaz Owned by: johnjamesjacoby's profile johnjamesjacoby
Milestone: 2.6 Priority: high
Severity: normal Version: 2.4.1
Component: Component - Forums 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
10 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
10 years ago

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

#3 @unsalkorkmaz
10 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
10 years ago

  • Component changed from General to Forums
  • Keywords needs-testing needs-patch added
  • Milestone changed from Awaiting Review to 2.5

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

Moving to 2.5 to investigate.

#5 @johnjamesjacoby
10 years ago

  • Milestone changed from 2.5 to 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
10 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, 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] => !=
                        )

                )
Version 0, edited 10 years ago by unsalkorkmaz (next)

#7 @alex-ye
10 years ago

  • Cc nashwan.doaqan@… added

#8 @johnjamesjacoby
10 years ago

  • Owner set to johnjamesjacoby
  • Resolution set to fixed
  • Status changed from new to 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 10 years ago by johnjamesjacoby (previous) (diff)
Note: See TracTickets for help on using tickets.