wordpress-develop/tests/phpunit/tests/post/getPageByTitle.php
Peter Wilson 0138b0dcd6 Posts, Post Types: Deprecate get_page_by_title() in favour of WP_Query.
Formally deprecate `get_page_by_title()`. In its current form the function is unpredictable in that it may return a result that leads to a 404 error and will return different results depending on the database version/engine combination used.

It is recommended developers use `WP_Query` instead:

{{{
$query = new WP_Query(
 array(
  'post_type' => 'page',
  'title'     => 'Sample Page',
 )
);
}}}


Props TimothyBlynJacobs, costdev, mukesh27, spacedmonkey, peterwilsoncc.
Fixes #57041.


git-svn-id: https://develop.svn.wordpress.org/trunk@55207 602fd350-edb4-49c9-b593-d223f7449a82
2023-02-03 03:56:10 +00:00

22 lines
389 B
PHP

<?php
/**
* @group post
*
* @covers ::get_page_by_title
*/
class Tests_Post_GetPageByTitle extends WP_UnitTestCase {
/**
* Tests that `get_page_by_title()` has been deprecated.
*
* @ticket 57041
*
* @expectedDeprecated get_page_by_title
*/
public function test_get_page_by_title_should_be_deprecated() {
$this->assertNull( get_page_by_title( '#57041 Page' ) );
}
}