Domanda

     
add_filter('query_vars', 'add_query_vars');
 
function add_rewrite_rules($aRules) {
    $aNewRules = array('societies/([^/]+)/?$' => 'index.php?pagename=societies&sid=$matches[1]');
    $aRules = $aNewRules + $aRules;
    return $aRules;
}
 
add_filter('rewrite_rules_array', 'add_rewrite_rules');


function add_query_vars($aVars) {
    $aVars[] = "page_id";    // represents the name of the variable as shown in the URL
    return $aVars;
}
 
add_filter('query_vars', 'add_query_vars');

So I'm attempting to use a custom get variable on redirect. Currently I have a redirect that takes you to a section of my site: zzz.net/dashboard?page_id=2278, for example but I'm getting a 404 page could not be displayed, so I added this code. Main issue is I really don't have the best idea of what I'm doing.

The reason I want to have ?page_id=2278, etc. on redirect is so I can know where the user just came from before they got to the dashboard page.

Advise and direction might be more helpful then just answers. Either way thank you for taking a moment to look at it.

È stato utile?

Soluzione

A GET variable named 'page_id' is utilized by the Wordpress core when querying any Page Objects.

Conversely, if you were to change the query to 'p=2786', then Wordpress would try and search for a Post with an ID of 2786.

By having that variable in your URL, Wordpress is getting confused and is trying to return a Page that has an ID of what is defined by your GET request. In order to prevent naming conflicts like these, it's always best to add a prefix to any named variables that are accessible within Global scope.

Change the name of your GET variable to something else (ie: WJ_page_id) to ensure you aren't conflicting with any main Wordpress variables.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top