Make WordPress Core

Ticket #24763: get_page_by_path_v3.patch

File get_page_by_path_v3.patch, 1.5 KB (added by zbtirrell, 11 years ago)

a 3rd version of this patch, only adds attachment when post type is scalar

  • wp-includes/post.php

     
    35133513 *
    35143514 * @param string $page_path Page path
    35153515 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
    3516  * @param string $post_type Optional. Post type. Default page.
     3516 * @param string|Array $post_type Optional. Post type or array of post types. Default page.
    35173517 * @return WP_Post|null WP_Post on success or null on failure
    35183518 */
    35193519function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') {
     
    35273527        $parts = array_map( 'sanitize_title_for_query', $parts );
    35283528
    35293529        $in_string = "'". implode( "','", $parts ) . "'";
    3530         $post_type_sql = esc_sql( $post_type );
    3531         $pages = $wpdb->get_results( "SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name IN ($in_string) AND (post_type = '$post_type_sql' OR post_type = 'attachment')", OBJECT_K );
    35323530
     3531        if ( is_array( $post_type ) ) {
     3532                $post_types = $post_type;
     3533        }
     3534        else {
     3535                $post_types = array( $post_type, 'attachment' );
     3536        }
     3537        $post_types = esc_sql( $post_types );
     3538
     3539        $post_type_in_string = "'" . implode( "','", $post_types ) . "'";
     3540
     3541        $pages = $wpdb->get_results( $sql = "SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name IN ($in_string) AND post_type IN ($post_type_in_string)", OBJECT_K );
     3542
    35333543        $revparts = array_reverse( $parts );
    35343544
    35353545        $foundid = 0;