WordPress.org

Make WordPress Core

Ticket #10865: get_post_by_title.patch

File get_post_by_title.patch, 889 bytes (added by sudar, 5 years ago)

Patch with get_post_by_title() function

  • post.php

     
    21282128} 
    21292129 
    21302130/** 
     2131 * Retrieve a post given its title. 
     2132 * 
     2133 * @uses $wpdb 
     2134 * 
     2135 * @param string $post_title Post title 
     2136 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. 
     2137 * @return mixed Post data if successful (type depends on $output) | Null if no posts found 
     2138 */ 
     2139function get_post_by_title($post_title, $output = OBJECT) { 
     2140        global $wpdb; 
     2141        $post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='post'", $post_title )); 
     2142        if ( $post ) 
     2143                return get_post($post, $output); 
     2144 
     2145        return null; 
     2146} 
     2147 
     2148/** 
    21312149 * Retrieve child pages from list of pages matching page ID. 
    21322150 * 
    21332151 * Matches against the pages parameter against the page ID. Also matches all