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 7725723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:00:44+00:00 2026-06-01T05:00:44+00:00

I finally got my permalinks working for Custom Post Types and Taxonomies using `

  • 0

I finally got my permalinks working for Custom Post Types and Taxonomies using `a helper class.

My custom post type is “menu” and my taxonomy is “menutype”.

I wrote the following rewrite:

function custom_rewrite( $wp_rewrite ) {
    $feed_rules = array(
        'menu/salads/(.+)'    =>  'index.php?menu=' . $wp_rewrite->preg_index(1),
        'menu/hotboxes/(.+)'    =>  'index.php?menu=' . $wp_rewrite->preg_index(1),
        'menu/wraps/(.+)'    =>  'index.php?menu=' . $wp_rewrite->preg_index(1),
        'menu/sauces/(.+)'    =>  'index.php?menu=' . $wp_rewrite->preg_index(1),
        'menu/soups/(.+)'    =>  'index.php?menu=' . $wp_rewrite->preg_index(1),
        '(.+)/([^/]+)(/[0-9]+)?/?$'    =>  'index.php?menutype=' . $wp_rewrite->preg_index(2)
    );

        $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
    }
    // refresh/flush permalinks in the dashboard if this is changed in any way
    add_filter( 'generate_rewrite_rules', 'custom_rewrite' ); 

The only thing is I would like to not hardcode the taxonomy (i.e menu/sauces/, menu/hotboxes) into my rewrite rules as the terms might change (but they will always be lowercase letters)

I tried the following:

'menu/([^/]+)/(.+)'

And also:

'menu/([a-z]+)/(.+)'

But neither worked.

  • 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-01T05:00:46+00:00Added an answer on June 1, 2026 at 5:00 am

    If you don’t need the reference to what follows menu/, then remove the parens there, e.g.

    menu/[^/]+/(.+)
    

    If you do need the reference, then make sure you’re passing the correct int argument to preg_index.

    As to “why does removing the parens work”, because including the parens around the first group [^/]+ creates a back-reference to what’s matched there. So when you call preg_index(1) you’re asking for the first match, when what you want is actually the 2nd match .+. You could also pass 2 to preg_index indicating that you want the 2nd matched group…but if you don’t need the first match it’s just wasted overhead to create the reference in the first place.

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

Sidebar

Related Questions

I have finally got a zend view helper working using this in my helper
I finally got apache2 with mod_wsgi working on Linux (havent much luck with windows
After many hair-pulling frustrations I've finally got one version of the PerlMagick module working
I've started working with ASP.net AJAX (finally ☺). and I've got an update panel
I finally got the Ws-Security working with CXF-BC & CXF-SE combination. I'm now trying
I finally got my django install working, however I'm noticing that the typical look
Hi I've finally got Suckerfish working and styled but in IE7 it is hidden
I've finally got this PHP email script working (didn't work on localhost…), but my
Have finally got a responsive site working (of a fashion). What I want to
I have been working on this Tab View and I finally got it working

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.