Skip to:
Content

bbPress.org

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#1493 closed defect (bug) (fixed)

bbp_pre_get_posts function problem

Reported by: alexvorn2's profile alexvorn2 Owned by:
Milestone: 2.0 Priority: high
Severity: normal Version: 1.1-alpha
Component: Back-end Keywords:
Cc:

Description (last modified by johnjamesjacoby)

Can you please change something in the bbp_pre_get_posts function?

when I delete this function my site work fine, but with this function an error occurs: Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs\wordpress10\wp-includes\query.php on line 27

I think you should modify this function somehow so the error will not show again.

My earlier post about this critical problem - http://bbpress.org/forums/topic/bbpress-plugin-updates/page/18#post-83617

Many Thanks!

Change History (8)

#1 @johnjamesjacoby
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [2970]) Adjustments to login and register forms to improve behavior and functionality.
Various documentation fixes.
Rename _bbp_topic_status meta to _bbp_status, and add migration routine to updater.
Sanity checks on $wp_query in bbp_pre_get_posts.

Fixes #1476, #1493. Props GautamGupta for original diff.

#2 @alexvorn2
14 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Thanks for the reply!
I downloaded the latest/updated r2970 plugin, but the error still occurs!

"Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs\wordpress10\wp-includes\query.php on line 27"

I can give a copy of my WordPress theme for testing: alexvorn.com/*removed*.zip

just extract the archive to the themes dir.

Last edited 14 years ago by alexvorn2 (previous) (diff)

#3 @johnjamesjacoby
14 years ago

  • Description modified (diff)

Can you confirm that it's bbPress that's causing this issue, and under what circumstance so I can duplicate it?

Thanks for linking me to your theme, but it won't be helpful to troubleshoot code that doesn't come with bbPress.

#4 @alexvorn2
14 years ago

Sure! Here you go:

$wpimpress_categories_obj = get_categories();
foreach ($wpimpress_categories_obj as $wpimpress_cat) {

$args=array(

'cat' => $wpimpress_cat->cat_ID,
'posts_per_page' => 1

);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);
if( have_posts() ) :

while ($wp_query->have_posts()) : $wp_query->the_post();

$all_post_ids .= $post->ID.',';

endwhile;

endif;
$wp_query = $temp;
wp_reset_query();

}

#5 @alexvorn2
14 years ago

add this to index.php , I use this code to show a list of ids from all categories that I need in my theme.

#6 @johnjamesjacoby
14 years ago

Does not appear to be a bbPress issue. You're unsetting the $wp_query global, which shouldn't happen naturally. Your code did however uncover a different fix that I will be applying shortly that should help prevent these errors even further.

For your code snippet, try this instead.

<?php

$wpimpress_categories_obj = get_categories();

foreach ( $wpimpress_categories_obj as $wpimpress_cat ) {
	$all_post_ids = '';
	$args = array(
		'cat'            => $wpimpress_cat->cat_ID,
		'posts_per_page' => 1
	);

	$new_query = new WP_Query( $args );

	if ( have_posts() ) :
		while ( $new_query->have_posts() ) : $new_query->the_post();
			$all_post_ids .= $post->ID.',';
		endwhile;
	endif;

	unset( $new_query );
}

?>

#7 @johnjamesjacoby
14 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [2977]) Rename $wp_query param in bbp_pre_get_posts to $posts_query to avoid conflict with $wp_query global.
Use $posts_query->get() in place of get_query_arg() to prevent errors in rare cases where $wp_query global is not set.
Fixes #1493 again.

#8 @alexvorn2
14 years ago

oh! Thanks! The problem was solved just with replacing the $wp_query with $new_query.

You Are The Best!

Note: See TracTickets for help on using tickets.