I have been wanting to do something similar like this for a long time. I have a url http://studionumberone.com/portfolio/obey-clothing/ which just shows the jquery gallery of images, I then have studionumberone.com/portfolio/obey-clothing/?view=all. Which shows all of the images in the gallery one above each other.

I would like the url to be studionumberone.com/portfolio/obey-clothing/all

The custom post type just does a basic:

<?php get_header(); 
$view = $_GET['view'];
<?php if ($view == "all") { ?>
show all images
<?php } else { ?>
show gallery shortcode 
<?php } ?>
<?php get_footer(); ?>

I have tried (no luck):

add_action( 'init', 'ss_permalinks' );
function ss_permalinks() {
add_filter( 'query_vars', 'ss_query_vars' );
function ss_query_vars( $query_vars ) {
    $query_vars[] = 'view';
    return $query_vars;

Hi @westondeboer:

Since you are saying your post type is 'portfolio' here's what works on my WordPress v3.0.4 test site with a 'portfolio' custom post type defined. It replaces all the code you have:

function yoursite_init() {
    'index.php?view=all&post_type=portfolio&name=$matches[1]', 'top');

  // Once you get working, remove this next line

You also need to flush your rewrite rules which you can do by saving your Permalinks in the admin console. Let me know if this solves your issue and if not please give me clarification.


You also need to capture the query parameter differently than using `$_GET['view']'; either of these will work:

// Option 1
$view = {$GLOBALS['wp']->query_vars['view'];

// Option 2
global $wp;
$view = $wp->query_vars['view'];
| improve this answer | |
  • you are correct in thinking my custom post type is portfolio. When I implement this, when I go to /portfolio/obey-clothing/all it redirects to /portfolio/obey-clothing/ – westondeboer Jan 24 '11 at 1:07
  • @westondeboer - That's what I get for posting without testing. Give me a sec... – MikeSchinkel Jan 24 '11 at 1:20
  • @westondeboer - BTW, where did service come from? – MikeSchinkel Jan 24 '11 at 1:22
  • @westondeboer - I've tested the code in WP 3.0.4 and created a full example. If that example does not work for you then one of your plugins or custom code in your theme is causing it to be overriden. You'll need to disable your plugins and test. – MikeSchinkel Jan 24 '11 at 1:38
  • 1
    So after a year and a couple of months, I was able to get this going. Works like magic! The reason why I didn't use it, is the client wanted something else right after I posted this question. But now I am back to what was originally posted. Thanks so much! – westondeboer Aug 22 '12 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.