WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#12287 closed defect (bug) (fixed)

Bug with : Query Posts, Post status and Custom Taxonomy

Reported by: momo360modena Owned by: ryan
Milestone: 3.0 Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: Cc:
PR Number:

Description

I use a category for a events section of my website. I filter on two criters, one custom taxonomy, and a default WordPress category.

The request :

query_posts( 'showposts=6&post_status=future&cat=7&taxonomy=departements&term=Gironde&order=ASC&orderby=date' )

The SQL query :

SELECT SQL_CALC_FOUND_ROWS wp_posts.*
FROM wp_posts
LEFT JOIN wp_posts AS p2

ON (wp_posts.post_parent = p2.ID)
WHERE 1=1 AND wp_posts.ID NOT IN ( SELECT tr.object_id FROM wp_term_relationships AS tr

INNER JOIN wp_term_taxonomy

AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id

WHERE tt.taxonomy = 'category'
AND tt.term_id IN ('7') )
AND wp_posts.ID IN (765, ... ,796)
AND wp_posts.post_type != 'revision'
AND (

(wp_posts.post_status = 'publish')
OR
(wp_posts.post_status = 'inherit' AND (p2.post_status = 'publish'))

)
ORDER BY wp_posts.post_date DESC
LIMIT 0, 4

The result :

I obtain post with the status publish and no future.

The cause :

line 1937, query.php, on trunk.
$qpost_status? = 'publish';

Why force post_status here ?
I precise that this request work without the custom taxonomy on query_posts();

Attachments (2)

query.diff (591 bytes) - added by momo360modena 10 years ago.
query.php.patch (1002 bytes) - added by momo360modena 10 years ago.
Add condition for status and type

Download all attachments as: .zip

Change History (10)

#1 @momo360modena
10 years ago

Argh... no edition. the same description with better format.

I use a category for a events section of my website. I filter on two criters, one custom taxonomy, and a default WordPress category.

The request :

query_posts( 'showposts=6&post_status=future&cat=7&taxonomy=departements&term=Gironde&order=ASC&orderby=date' )

The SQL query :

SELECT SQL_CALC_FOUND_ROWS wp_posts.* 
FROM wp_posts 
LEFT JOIN wp_posts AS p2 
	ON (wp_posts.post_parent = p2.ID) 
	WHERE 1=1 AND wp_posts.ID NOT IN ( SELECT tr.object_id FROM wp_term_relationships AS tr 
INNER JOIN wp_term_taxonomy 
	AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy = 'category' 
AND tt.term_id IN ('7') ) 
AND wp_posts.ID IN (765, ... ,796) 
AND wp_posts.post_type != 'revision' 
AND (
	(wp_posts.post_status = 'publish') 
	OR 
	(wp_posts.post_status = 'inherit' AND (p2.post_status = 'publish'))
) 
ORDER BY wp_posts.post_date DESC 
LIMIT 0, 4

The result :

I obtain post with the status publish and no future.

The cause :

line 1937, query.php, on trunk.

$q['post_status'] = 'publish';

Why force post_status here ?
I precise that this request work without the custom taxonomy on query_posts();

#2 @ryan
10 years ago

It was probably done to force evaluation of the post status block that comes later. I think we change that line to set the status to publish only if it is not already set.

#3 @momo360modena
10 years ago

I add this line temporary:

if ( !isset($q['post_status']) || empty($q['post_status']) )
    $q['post_status'] = 'publish';

#4 @momo360modena
10 years ago

  • Keywords has-patch needs-testing added

@momo360modena
10 years ago

#5 @momo360modena
10 years ago

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

Prefer this ticket : ticket:12856

#6 @nacin
10 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

@momo360modena
10 years ago

Add condition for status and type

#7 @momo360modena
10 years ago

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

Bug fixed on changeset:14478

#8 @momo360modena
10 years ago

  • Keywords has-patch needs-testing removed
Note: See TracTickets for help on using tickets.