Changeset 55207 for trunk/src/wp-includes/post.php
- Timestamp:
- 02/03/2023 03:56:10 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r55202 r55207 5753 5753 5754 5754 /** 5755 * Retrieves a page given its title.5756 *5757 * If more than one post uses the same title, the post with the smallest ID will be returned.5758 * Be careful: in case of more than one post having the same title, it will check the oldest5759 * publication date, not the smallest ID.5760 *5761 * Because this function uses the MySQL '=' comparison, $page_title will usually be matched5762 * as case-insensitive with default collation.5763 *5764 * @since 2.1.05765 * @since 3.0.0 The `$post_type` parameter was added.5766 *5767 * @global wpdb $wpdb WordPress database abstraction object.5768 *5769 * @param string $page_title Page title.5770 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which5771 * correspond to a WP_Post object, an associative array, or a numeric array,5772 * respectively. Default OBJECT.5773 * @param string|array $post_type Optional. Post type or array of post types. Default 'page'.5774 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure.5775 */5776 function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {5777 global $wpdb;5778 5779 if ( is_array( $post_type ) ) {5780 $post_type = esc_sql( $post_type );5781 $post_type_in_string = "'" . implode( "','", $post_type ) . "'";5782 $sql = $wpdb->prepare(5783 "5784 SELECT ID5785 FROM $wpdb->posts5786 WHERE post_title = %s5787 AND post_type IN ($post_type_in_string)5788 ",5789 $page_title5790 );5791 } else {5792 $sql = $wpdb->prepare(5793 "5794 SELECT ID5795 FROM $wpdb->posts5796 WHERE post_title = %s5797 AND post_type = %s5798 ",5799 $page_title,5800 $post_type5801 );5802 }5803 5804 $page = $wpdb->get_var( $sql );5805 5806 if ( $page ) {5807 return get_post( $page, $output );5808 }5809 5810 return null;5811 }5812 5813 /**5814 5755 * Identifies descendants of a given page ID in a list of page objects. 5815 5756 *
Note: See TracChangeset
for help on using the changeset viewer.