WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#40574 closed defect (bug) (worksforme)

REST API orderby filter giving wrong output

Reported by: subrataemfluence Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.4
Component: REST API Keywords: reporter-feedback
Focuses: rest-api Cc:

Description

When using title as orderby filter in REST API endpoint the I am getting wrong output.

Test cases:

[Case -A]

/wp-json/wp/v2/api/trips?filter[orderby]=title&order=asc&per_page=1

Desired output (post title): "Amritsar, the city of Golden Temple"
Actual output (post title): "Auli Ski Resort"

[Case -B]

/wp-json/wp/v2/api/trips?filter[orderby]=title&per_page=1

Desired output (post title): "Amritsar, the city of Golden Temple"
Actual output (post title): "Dharamsala - The deemed smart City"

I did not specify any order as the default order in any query is supposed to be Ascending.

[Case - C]

/wp-json/wp/v2/api/trips?filter[orderby]=title&order=desc&per_page=1

Desired output (post title): "Sundarvans - the largest mangrove forest"
Actual output (post title): "Dharamsala - The deemed smart City"

To cross check I tested with other custom post type but here again REST API gave me wrong result.

Change History (4)

#1 follow-up: @ocean90
3 years ago

  • Keywords reporter-feedback added

Hello @subrataemfluence, the filter parameter has been removed in [38968], see #38378. Are you using the https://github.com/wp-api/rest-filter plugin?

#2 in reply to: ↑ 1 @subrataemfluence
3 years ago

Thank you for your response. I am not using any plugin and rather I would like to code it by hand. The reason is I am new to WP and hence like to understand how things actually work. Don't I have an option to go without plugin?

Replying to ocean90:

Hello @subrataemfluence, the filter parameter has been removed in [38968], see #38378. Are you using the https://github.com/wp-api/rest-filter plugin?

#3 @Soean
3 years ago

@subrataemfluence You can use /wp-json/wp/v2/api/trips?orderby=title&per_page=1

#4 @rmccue
3 years ago

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

Per @Soean's comment, this is possible, but you need the orderby parameter not filter[orderby]

Note: See TracTickets for help on using tickets.