WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/22/2015 04:58:21 PM (5 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/results.php

    r31324 r33706  
    704704    }
    705705
     706    function test_title() {
     707        $title = 'Tacos are Cool';
     708        $post_id = $this->factory->post->create( array(
     709            'post_title' => $title,
     710            'post_type' => 'post',
     711            'post_status' => 'publish'
     712        ) );
     713
     714        $result1 = $this->q->query( array( 'title' => $title, 'fields' => 'ids' ) );
     715        $this->assertCount( 1, $result1 );
     716        $this->assertContains( $post_id, $result1 );
     717
     718        $result2 = $this->q->query( array( 'title' => 'Tacos', 'fields' => 'ids' ) );
     719        $this->assertCount( 0, $result2 );
     720    }
    706721}
Note: See TracChangeset for help on using the changeset viewer.