Changeset 54783 for branches/6.1/src/wp-includes/post.php
- Timestamp:
- 11/10/2022 02:19:05 AM (2 years ago)
- Location:
- branches/6.1
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.1
-
branches/6.1/src/wp-includes/post.php
r54713 r54783 5767 5767 * @since 3.0.0 The `$post_type` parameter was added. 5768 5768 * 5769 * @global wpdb $wpdb WordPress database abstraction object. 5770 * 5769 5771 * @param string $page_title Page title. 5770 5772 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which … … 5775 5777 */ 5776 5778 function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) { 5777 $args = array( 5778 'title' => $page_title, 5779 'post_type' => $post_type, 5780 'post_status' => get_post_stati(), 5781 'posts_per_page' => 1, 5782 'update_post_term_cache' => false, 5783 'update_post_meta_cache' => false, 5784 'no_found_rows' => true, 5785 'orderby' => 'post_date ID', 5786 'order' => 'ASC', 5787 ); 5788 $query = new WP_Query( $args ); 5789 $pages = $query->posts; 5790 5791 if ( empty( $pages ) ) { 5792 return null; 5793 } 5794 5795 return get_post( $pages[0], $output ); 5779 global $wpdb; 5780 5781 if ( is_array( $post_type ) ) { 5782 $post_type = esc_sql( $post_type ); 5783 $post_type_in_string = "'" . implode( "','", $post_type ) . "'"; 5784 $sql = $wpdb->prepare( 5785 " 5786 SELECT ID 5787 FROM $wpdb->posts 5788 WHERE post_title = %s 5789 AND post_type IN ($post_type_in_string) 5790 ", 5791 $page_title 5792 ); 5793 } else { 5794 $sql = $wpdb->prepare( 5795 " 5796 SELECT ID 5797 FROM $wpdb->posts 5798 WHERE post_title = %s 5799 AND post_type = %s 5800 ", 5801 $page_title, 5802 $post_type 5803 ); 5804 } 5805 5806 $page = $wpdb->get_var( $sql ); 5807 5808 if ( $page ) { 5809 return get_post( $page, $output ); 5810 } 5811 5812 return null; 5796 5813 } 5797 5814
Note: See TracChangeset
for help on using the changeset viewer.