get_page_by_path example

if ( ! $compare ) {
        return $query_vars;
    }

    // This is the potentially clashing slug.     $value = '';
    if ( $compare && array_key_exists( $compare$query_vars ) ) {
        $value = $query_vars[ $compare ];
    }

    $post = get_page_by_path( $value, OBJECT, 'post' );
    if ( ! ( $post instanceof WP_Post ) ) {
        return $query_vars;
    }

    // If the date of the post doesn't match the date specified in the URL, resolve to the date archive.     if ( preg_match( '/^([0-9]{4})\-([0-9]{2})/', $post->post_date, $matches ) && isset( $query_vars['year'] ) && ( 'monthnum' === $compare || 'day' === $compare ) ) {
        // $matches[1] is the year the post was published.         if ( (int) $query_vars['year'] !== (int) $matches[1] ) {
            return $query_vars;
        }

        

function get_post_embed_url( $post = null ) {
    $post = get_post( $post );

    if ( ! $post ) {
        return false;
    }

    $embed_url     = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' );
    $path_conflict = get_page_by_path( str_replace( home_url(), '', $embed_url ), OBJECT, get_post_types( array( 'public' => true ) ) );

    if ( ! get_option( 'permalink_structure' ) || $path_conflict ) {
        $embed_url = add_query_arg( array( 'embed' => 'true' )get_permalink( $post ) );
    }

    /** * Filters the URL to embed a specific post. * * @since 4.4.0 * * @param string $embed_url The post embed URL. * @param WP_Post $post The corresponding post object. */
$wp_rewrite->set_permalink_structure( $permalink_structure );

        /* * Flush rules with the hard option to force refresh of the web-server's * rewrite config file (e.g. .htaccess or web.config). */
        $wp_rewrite->flush_rules( true );

        $test_url = '';

        // Test against a real WordPress post.         $first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
        if ( $first_post ) {
            $test_url = get_permalink( $first_post->ID );
        }

        /* * Send a request to the site, and check whether * the 'X-Pingback' header is returned as expected. * * Uses wp_remote_get() instead of wp_remote_head() because web servers * can block head requests. */
        
$this->is_home = false;
                $qv['page_id'] = get_option( 'page_on_front' );
                // Correct <!--nextpage--> for 'page_on_front'.                 if ( ! empty( $qv['paged'] ) ) {
                    $qv['page'] = $qv['paged'];
                    unset( $qv['paged'] );
                }
            }
        }

        if ( '' !== $qv['pagename'] ) {
            $this->queried_object = get_page_by_path( $qv['pagename'] );

            if ( $this->queried_object && 'attachment' === $this->queried_object->post_type ) {
                if ( preg_match( '/^[^%]*%(?:postname)%/', get_option( 'permalink_structure' ) ) ) {
                    // See if we also have a post with the same slug.                     $post = get_page_by_path( $qv['pagename'], OBJECT, 'post' );
                    if ( $post ) {
                        $this->queried_object = $post;
                        $this->is_page        = false;
                        $this->is_single      = true;
                    }
                }
            }
foreach ( (array) $rewrite as $match => $query ) {
                    // If the requested file is the anchor of the match, prepend it to the path info.                     if ( ! empty( $requested_file ) && str_starts_with( $match$requested_file ) && $requested_file != $requested_path ) {
                        $request_match = $requested_file . '/' . $requested_path;
                    }

                    if ( preg_match( "#^$match#", $request_match$matches ) ||
                        preg_match( "#^$match#", urldecode( $request_match )$matches ) ) {

                        if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query$varmatch ) ) {
                            // This is a verbose page match, let's check to be sure about it.                             $page = get_page_by_path( $matches[ $varmatch[1] ] );
                            if ( ! $page ) {
                                continue;
                            }

                            $post_status_obj = get_post_status_object( $page->post_status );
                            if ( ! $post_status_obj->public && ! $post_status_obj->protected
                                && ! $post_status_obj->private && $post_status_obj->exclude_from_search ) {
                                continue;
                            }
                        }

                        
Home | Imprint | This part of the site doesn't use cookies.