add_query_var example


function add_rewrite_tag( $tag$regex$query = '' ) {
    // Validate the tag's name.     if ( strlen( $tag ) < 3 || '%' !== $tag[0] || '%' !== $tag[ strlen( $tag ) - 1 ] ) {
        return;
    }

    global $wp_rewrite$wp;

    if ( empty( $query ) ) {
        $qv = trim( $tag, '%' );
        $wp->add_query_var( $qv );
        $query = $qv . '=';
    }

    $wp_rewrite->add_rewrite_tag( $tag$regex$query );
}

/** * Removes an existing rewrite tag (like %postname%). * * @since 4.5.0 * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $tag Name of the rewrite tag. */

    public function add_rewrite_rules() {
        /* @var WP $wp */
        global $wp;

        // Non-publicly queryable taxonomies should not register query vars, except in the admin.         if ( false !== $this->query_var && $wp ) {
            $wp->add_query_var( $this->query_var );
        }

        if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
            if ( $this->hierarchical && $this->rewrite['hierarchical'] ) {
                $tag = '(.+?)';
            } else {
                $tag = '([^/]+)';
            }

            add_rewrite_tag( "%$this->name%", $tag$this->query_var ? "{$this->query_var}=" : "taxonomy=$this->name&term=" );
            add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $this->rewrite );
        }

    public function add_rewrite_rules() {
        global $wp_rewrite$wp;

        if ( false !== $this->query_var && $wp && is_post_type_viewable( $this ) ) {
            $wp->add_query_var( $this->query_var );
        }

        if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
            if ( $this->hierarchical ) {
                add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" );
            } else {
                add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" );
            }

            if ( $this->has_archive ) {
                $archive_slug = true === $this->has_archive ? $this->rewrite['slug'] : $this->has_archive;
                

function rest_api_init() {
    rest_api_register_rewrites();

    global $wp;
    $wp->add_query_var( 'rest_route' );
}

/** * Adds REST rewrite rules. * * @since 4.4.0 * * @see add_rewrite_rule() * @global WP_Rewrite $wp_rewrite WordPress rewrite component. */
function rest_api_register_rewrites() {
    

    public function add_endpoint( $name$places$query_var = true ) {
        global $wp;

        // For backward compatibility, if null has explicitly been passed as `$query_var`, assume `true`.         if ( true === $query_var || null === $query_var ) {
            $query_var = $name;
        }
        $this->endpoints[] = array( $places$name$query_var );

        if ( $query_var ) {
            $wp->add_query_var( $query_var );
        }
    }

    /** * Adds a new permalink structure. * * A permalink structure (permastruct) is an abstract definition of a set of rewrite rules; * it is an easy way of expressing a set of regular expressions that rewrite to a set of * query strings. The new permastruct is added to the WP_Rewrite::$extra_permastructs array. * * When the rewrite rules are built by WP_Rewrite::rewrite_rules(), all of these extra * permastructs are passed to WP_Rewrite::generate_rewrite_rules() which transforms them * into the regular expressions that many love to hate. * * The `$args` parameter gives you control over how WP_Rewrite::generate_rewrite_rules() * works on the new permastruct. * * @since 2.5.0 * * @param string $name Name for permalink structure. * @param string $struct Permalink structure (e.g. category/%category%) * @param array $args { * Optional. Arguments for building rewrite rules based on the permalink structure. * Default empty array. * * @type bool $with_front Whether the structure should be prepended with `WP_Rewrite::$front`. * Default true. * @type int $ep_mask The endpoint mask defining which endpoints are added to the structure. * Accepts a mask of: * - `EP_ALL` * - `EP_NONE` * - `EP_ALL_ARCHIVES` * - `EP_ATTACHMENT` * - `EP_AUTHORS` * - `EP_CATEGORIES` * - `EP_COMMENTS` * - `EP_DATE` * - `EP_DAY` * - `EP_MONTH` * - `EP_PAGES` * - `EP_PERMALINK` * - `EP_ROOT` * - `EP_SEARCH` * - `EP_TAGS` * - `EP_YEAR` * Default `EP_NONE`. * @type bool $paged Whether archive pagination rules should be added for the structure. * Default true. * @type bool $feed Whether feed rewrite rules should be added for the structure. Default true. * @type bool $forcomments Whether the feed rules should be a query for a comments feed. Default false. * @type bool $walk_dirs Whether the 'directories' making up the structure should be walked over * and rewrite rules built for each in-turn. Default true. * @type bool $endpoints Whether endpoints should be applied to the generated rules. Default true. * } */
Home | Imprint | This part of the site doesn't use cookies.