get_page_by_title()通过页面的标题获取页面信息

目录

描述

Retrieves a post given its title. If more than one post uses the same title, the post with the smallest ID will be returned.

Because this function uses the MySQL '=' comparison the $page_title will usually be matched as case insensitive with default collating.

get_page_by_title() 描述

用法


<?php 
  get_page_by_title
$page_title$output$post_type );
?>

get_page_by_title() 用法

参数

$page_title

(string) (必填) Page title

默认值: None

$output

(string) (可选) Output type. OBJECT, ARRAY_N, or ARRAY_A.

默认值: OBJECT

$post_type

(string) (可选) Post type.

默认值: page

get_page_by_title() 参数

返回值

(mixed) 

OBJECT, ARRAY_N, or ARRAY_A.

NULL when no posts found.

get_page_by_title() 返回值

示例

Find Page ID to use with exclude in wp_list_pages

This example will return the $page object for the page titled "About". Then the $page->ID element is used to exclude the About page when listing pages.

How To Find WordPress Page ID By Title Then Replace the_content()

In this example, we find the page id of "Sample Page" then replace the page's the_content() with "Hello World!"

get_page_by_title() 示例

注意

  • 使用到 global: (object) $wpdb

get_page_by_title() 注意

历史

  • 添加于 版本: 2.1.0
  • 3.0.0: $post_type Parameter was added.

get_page_by_title() 历史

源文件

get_page_by_title() 函数的代码位于 wp-includes/post.php.

get_page_by_title() 源文件

相关