Make WordPress Core

Opened 12 years ago

Closed 11 years ago

#22995 closed defect (bug) (wontfix)

WP_Query Category stuff blank page

Reported by: ninos-ego's profile Ninos Ego Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5
Component: Query Keywords:
Focuses: Cc:

Description

hey there,
maybe I have found a bug. Sending following parameter to the WP Query (with my theme via ?s=test%cat=1234) you should get a blank page. At first I thought it was a bug of mine, but deleting following line in /wp-includes/query.php:1746 fixes the problem.

$q['category__in'][] = $cat;

So I think there's a bug in the query function...

Thanks,
Ninos

Change History (12)

#1 @alexvorn2
12 years ago

so you want to say that there is a problem in filtering search results by category?
first of all why ?s=test%cat=1234 and not ?s=test&cat=1234

#2 follow-up: @markoheijnen
12 years ago

  • Keywords reporter-feedback added

Need more feedback. It sounds like you doing something wrong and without any details about errors there isn't something to say. Please test it out what is wrong with WP_DEBUG true.

#3 in reply to: ↑ 2 @Ninos Ego
12 years ago

Replying to alexvorn2:

first of all why ?s=test%cat=1234 and not ?s=test&cat=1234

sry typo :D

Replying to markoheijnen:

Need more feedback. It sounds like you doing something wrong and without any details about errors there isn't something to say. Please test it out what is wrong with WP_DEBUG true.

Debug was set to true, but there was no error. This bug is strange, I just get a blank page :/ In my theme I do not use the request "cat" anywhere, so I cannot understand, why this error happens.

My only clue is the line 1746 in the query.php...

#4 @markoheijnen
12 years ago

That is just random code. For what I can guess it seems a conflict with your theme or the plugins you are using.
I think your issue is better to be handled on http://wordpress.org/support/ and not here.

#5 @SergeyBiryukov
12 years ago

?s=test&cat=1234 throws two notices:

Notice: Trying to get property of non-object in wp-includes/general-template.php on line 1651
Notice: Trying to get property of non-object in wp-includes/general-template.php on line 1652

The code in question:
http://core.trac.wordpress.org/browser/tags/3.5/wp-includes/general-template.php#L1648

Related: #18614, #21394

#6 @markoheijnen
12 years ago

Yeah confirmed that. Only happens when the category can't be found. looking to the code all calls to get_queried_object() are weird since there is no check at all.

That said that shouldn't cause a blank page.

#7 @markoheijnen
12 years ago

Added the patch for that fix to #21394.
Still more feedback of the user is needed on the reason why he gets a blank page. Do you get this where the cat is found or when it isn't found?

#8 follow-up: @Ninos Ego
12 years ago

Think I have found the bug. Adding a non existing category id I get the descripted error.
On line /wp-includes/query.php:1745-1751 you should check the id:
just replace:

if ( $in ) {
	$q['category__in'][] = $cat;
	$q['category__in'] = array_merge( $q['category__in'], get_term_children($cat, 'category') );
} else {
	$q['category__not_in'][] = $cat;
	$q['category__not_in'] = array_merge( $q['category__not_in'], get_term_children($cat, 'category') );
}

with:

if( get_category($cat, false) ) {
	if ( $in ) {
		$q['category__in'][] = $cat;
		$q['category__in'] = array_merge( $q['category__in'], get_term_children($cat, 'category') );
	} else {
		$q['category__not_in'][] = $cat;
		$q['category__not_in'] = array_merge( $q['category__not_in'], get_term_children($cat, 'category') );
	}
}

Otherwise
$q['category__in'] or $q['category__not_in'] have got a wrong ID and send it in line /wp-includes/query.php:1761-1766

$tax_query[] = array(
	'taxonomy' => 'category',
	'terms' => $q['category__in'],
	'field' => 'term_id',
	'include_children' => false
);

and in line /wp-includes/query.php:1771-1776

$tax_query[] = array(
	'taxonomy' => 'category',
	'terms' => $q['category__not_in'],
	'operator' => 'NOT IN',
	'include_children' => false
);

to the tax query. Because of that I get a blank page.

Last edited 12 years ago by Ninos Ego (previous) (diff)

#9 in reply to: ↑ 8 @SergeyBiryukov
12 years ago

Replying to Ninos Ego:

Otherwise $q['category__in'] or $q['category__not_in'] have got a wrong ID

That still shouldn't cause a blank page.

ticket:21394:21394.general-template.diff looks like the proper fix for the notice.

#10 @markoheijnen
12 years ago

Also that is not the problem. You should be able to send in non existing id's and that the query is going to listen to it.

And I agree with Sergey that it shouldn't cause a blank page. I think it's better you try to solve your problem through the forum and by that closing this ticket.

#11 @Ninos Ego
12 years ago

  • Keywords reporter-feedback removed

all my filters, plugins and action hooks are deactivated. I have deleted all query posts etc. but have not found the error in my theme. I think it's a wordpress bug, bacause my patch is working fine. But I will still search the bug in my theme, because other theme have not this problem...

#12 @wonderboymusic
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

#21394 has a patch in 3.7 that fixes a bunch of queried_object instances, let's focus the attention there

Note: See TracTickets for help on using tickets.