Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#45868 closed defect (bug) (invalid)

Creating a custom post type with the name of "order" breaks sorting

Reported by: calvintennant's profile calvintennant Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: Cc:

Description

Using the specific custom post type name "order" causes incorrect sql to be generated in WP_Query and in WP_List_Table. It is easily reproduced by creating a custom post type named "order" and trying to sort list of posts in the wordpress admin. It should be noted that the sorting functionality breaks for all content types after adding the "order" content type, it is not isolated to the new type but even the default "posts" type will no longer sort.

When sorting the table (after clicking "title" in the wordpress admin) a query like the one below is generated:

<?php
SELECT   posts.* FROM posts  WHERE 1=1  AND posts.post_name = 'asc' AND posts.post_type = 'order'  ORDER BY posts.post_title

Look specifically at the "WHERE"

<?php
AND posts.post_name = 'asc'

I was able to work around this bug by changing the name of my custom post type from "order" to something else.

Change History (1)

#1 @ocean90
6 years ago

  • Component changed from General to Query
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hello @calvintennant, welcome to WordPress Trac!

There's a list of reserved terms which cannot be used for custom post types, taxonomies or in request variables. You can find the list at https://codex.wordpress.org/Reserved_Terms.

Note: See TracTickets for help on using tickets.