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

  • Home
  • SEARCH
  • 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 8820457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:36:46+00:00 2026-06-14T05:36:46+00:00

I am having trouble getting WordPress to assign the proper values to variables using

  • 0

I am having trouble getting WordPress to assign the proper values to variables using the add_rewrite_rule() function. My goal is to have a url that looks like this: www.mywebsite.com/catalog/category1/category2/item-slug.

Here is my code from the functions.php file:

add_filter( 'query_vars', 'query_vars_new' );
function query_vars_new($query_vars){
    $query_vars[]='category1';
    $query_vars[]='category2';
    $query_vars[]='catalog_item';
    return $query_vars;
}

add_action( 'init', 'rewrite_init' );
function rewrite_init(){
    add_rewrite_rule('catalog(/([^/]+))?(/([^/]+))?/?','index.php?page_id=94&category1=$matches[1]&category2=$matches[2]&catalog_item=$matches[3]','top');
}

So the goal is to have three variables $category1, $category2, and $catalog_item with the values from the corresponding url segments. However, when I test this the first two variables are set to the same value.

For example, www.mywebsite.com/catalog/clothes/shirts/polo-shirt should return:

$category1="clothes";
$category2="shirts";
$catalog_item="polo-shirt";

But instead I get:

$category1="/clothes";
$category2="clothes";
$catalog_item="/polo-shirt";

There must be something wrong with my add_rewrite_rule function, but I can’t figure it out.

  • 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-06-14T05:36:48+00:00Added an answer on June 14, 2026 at 5:36 am

    Thanks to the incredibly underwhelming response to this question I ended up just making it work without the help of the WordPress variables. I just configured WordPress to allow the variables in the url, then used PHP to fetch the URL and get the different URL segments and analyze them. Not quite as pretty as the WordPress method, but at least it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having trouble getting my JTable that im using to display either check boxes
Having trouble getting this to work. What's strange is that I have 10 bookmarks
I am having trouble getting this code to run using Google Chrome(I have not
im having trouble getting a string (containing a URL) from one activity to another.
I'm having trouble getting Tire working using ElasticSearch with the Bonsai addon on the
I'm currently having trouble getting example code for using tweepy to access Twitter's Streaming
I'm having trouble getting Japanese text to display properly on a website compiled using
I'm having trouble getting OpenGL 3.2 to run on Lion (osx 10.7.4) using Derelict3
Having trouble getting my POST arrays to show all checkbox values from my form.
Im having trouble getting a function within a function working, do you think what

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.