Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#40239 closed defect (bug) (invalid)

Getting posts by post_name is broken

Reported by: programmin's profile programmin Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

Getting posts by the post_name, or slug, is currently broken... or the documentation is broken:

<?php
var_dump(get_posts( array(
                                'post_name' => 'anyreallyuniquename',
                                'post_status' => 'any'
)));

Why in the world should this be a listing of 5 recent posts?

Change History (1)

#1 @peterwilsoncc
7 years ago

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

@programmin,

The correct argument is name rather than post_name, there's an example on the dev reference site. For a full list of arguments, see WP_Query:parse_query()'s documentation but be aware there are some differences in behaviour.

I'll close this ticket off for now but feel free to followup if I'm missing something.

Note: See TracTickets for help on using tickets.