Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#33074 closed enhancement (fixed)

Query by post_title

Reported by: wonderboymusic's profile wonderboymusic Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 1.5
Component: Query Keywords: has-patch needs-unit-tests
Focuses: Cc:

Description

If you are using wp_posts as an object store, sometimes you want to do an exists lookup by "name" or "title" - here's what doing that now looks like:

$tacos = get_posts( [
  'post_type' => 'taco',
  's' => $name,
  'exact' => true,
  'sentence' => true,
  'post_status' => 'publish',
  'fields' => 'ids',
  'posts_per_page' => 1
] );

I don't want to hear any arguments about performance without an acknowledgment that LIKE wildcard searches against serialized meta_values exist.

Attachments (2)

33074.diff (3.1 KB) - added by wonderboymusic 9 years ago.
33074.2.patch (574 bytes) - added by dimadin 9 years ago.

Download all attachments as: .zip

Change History (10)

#2 @wonderboymusic
9 years ago

  • Milestone changed from Future Release to 4.4

@wonderboymusic
9 years ago

#3 @wonderboymusic
9 years ago

  • Keywords has-patch commit added; needs-patch good-first-bug removed

33074.diff accomplishes this

#4 @boonebgorges
9 years ago

  • Keywords needs-unit-tests added; commit removed

#5 follow-up: @wonderboymusic
9 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 33706:

Query:

Add a query var, title, that allows you to query posts by post_title. To accomplish this now, you have to do something like:

$tacos = get_posts( [
  'post_type' => 'taco',
  's' => $name,
  'exact' => true,
  'sentence' => true,
  'post_status' => 'publish',
  'fields' => 'ids',
  'posts_per_page' => 1
] );

Adds unit tests.

Fixes #33074.

#6 in reply to: ↑ 5 @dimadin
9 years ago

Replying to wonderboymusic:

Missing changelog. There is already a changelog for 4.4 from when post_name__in was introduced ([33653], [33661]), so maybe just expanding it?

@dimadin
9 years ago

#7 @DrewAPicture
9 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#8 @wonderboymusic
9 years ago

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

In 33722:

WP_Query: add changelog for the title param after [33706]

Props dimadin.
Fixes #33074.

Note: See TracTickets for help on using tickets.