WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#33074 closed enhancement (fixed)

Query by post_title

Reported by: wonderboymusic Owned by: 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 3 years ago.
33074.2.patch (574 bytes) - added by dimadin 3 years ago.

Download all attachments as: .zip

Change History (10)

#2 @wonderboymusic
3 years ago

  • Milestone changed from Future Release to 4.4

@wonderboymusic
3 years ago

#3 @wonderboymusic
3 years ago

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

33074.diff accomplishes this

#4 @boonebgorges
3 years ago

  • Keywords needs-unit-tests added; commit removed

#5 follow-up: @wonderboymusic
3 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
3 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
3 years ago

#7 @DrewAPicture
3 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#8 @wonderboymusic
3 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.