WordPress keeps removing query var from the URL

Question

I have a custom post type "press-release" that I pass a query var to the template through the URL. The URL structure looks like this.

MYDOMAIN.COM/press-release/TITLE-OF-RELEASE/?client=123

When I go to the url everything works as expected. I am able to grab the value from the query var. The issue I have is on page load WordPress then rewrites the URL to be:

MYDOMAIN.COM/press-release/TITLE-OF-RELEASE/

I need to keep the query var in the URL structure so people can share the URL.

I have tried many options but no success so far. Does anyone know why WordPress is doing this and how it can be fixed so my query var does not get removed from the URL?

UPDATE: I have tried this but no success

add_action('init', 'add_client_url');
function add_client_url() {
  global $wp,$wp_rewrite;
  $wp->add_query_var('client');
  $wp_rewrite->add_rule('client/([^/]+)','index.php?client=$matches[1]','top');
  $wp_rewrite->flush_rules(false);
}
0
Jason 2 months 0 Answers 11 views 0

Leave an answer