Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7159201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:11:30+00:00 2026-05-28T13:11:30+00:00

Problem I want to rewrite my GET-variable to /demo/. My current permalink structure: /my-new-post/?demo=true

  • 0

Problem

I want to rewrite my GET-variable to /demo/.

My current permalink structure:
/my-new-post/?demo=true

What I want:
/my-new-post/demo/

I have this code:

It allows the “demo” $_GET variable and then echo “true”. It works, just the rewrite part left.

<?php
add_filter('query_vars', 'queryvars' );
add_action('parse_query', 'echo_query_var');

function queryvars( $qvars )
{
    $qvars[] = 'demo';
    return $qvars;
}

function echo_query_var() {
    echo get_query_var('demo');
}
?>

Additional information

  • It should work with all posts (not just “my-new-post”).
  • It should not return 404.
  • I should be able to get the post ID.
  • GET variable “demo” can be true, or empty. Not important.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:11:31+00:00Added an answer on May 28, 2026 at 1:11 pm

    This works so far…

    // Actions - Rewrite rules
    add_filter('query_vars', array($wp_comment_pages, 'add_get_variable'));
    add_action('generate_rewrite_rules', array($wp_comment_pages, 'add_rewrite_rule'));
    
    // Plugin container
    class wp_comment_pages
    {   
        // Flush the rules - only needed once
        function flush_rules()
        {
            global $wp_rewrite;
            $wp_rewrite->flush_rules();
        }
    
        // Add get variable to query vars
        function add_get_variable($public_query_vars)
        {
            $public_query_vars[] = 'demo';
            return $public_query_vars;
        }
    
        // Generate permalinks
        function add_rewrite_rule($wp_rewrite)
        {
            $new_rules = array(
                '(.+)/demo' => 'index.php?p=' . $wp_rewrite->preg_index(1) . '&demo=true'
            );
    
            $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a similar problem with this ( https://wordpress.stackexchange.com/questions/9593/custom-post-type-archive-with-pagination ) and can't really figure
I have an older form that I really don't want to rewrite at this
The Problem I want to press a key when I have a line highlighted
I'm experiencing this problem: I want to add the Google Maps API to my
I have this rewrite rule that turns foo.com/test (or foo.com/test/) into foo.com/test.txt: RewriteRule ^test/?$
I'm using GET requests in my project and I want to rewrite URLs in
I have problem with my .htaccess redirections. Say I want to change http://www.domain.com/login.php into
Using Mono.Cecil I want to rewrite the following property: public string FirstName { get
I have an installation of CodeIgniter. Basically, my directory structure looks like this: |
Okey, so this is my problem. I want to use mod_rewrite to make nice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.