#1493 closed defect (bug) (fixed)
bbp_pre_get_posts function problem
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 2.0 | Priority: | high |
Severity: | normal | Version: | 1.1-alpha |
Component: | Back-end | Keywords: | |
Cc: |
Description (last modified by )
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)
#2
@
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.
#3
@
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
@
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
@
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
@
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 ); } ?>
(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.