Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created October 14, 2011 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/1287996 to your computer and use it in GitHub Desktop.
Save billerickson/1287996 to your computer and use it in GitHub Desktop.
I created a rewrite endpoint called 'filter' which I'm going to use to toggle between
the standard blog post view (most recent posts), and most comments view (/filter/comments)
The code is really simple: https://gist.github.com/1285290
And it works great for the main blog page:
http://localhost:8888/dev-bachis/blog/ displays all posts in order of post date
http://localhost:8888/dev-bachis/blog/filter/comments displays all posts in
order of most comments
But it 404s on category pages
http://localhost:8888/dev-bachis/category/uncategorized/filter/comments - 404
http://localhost:8888/dev-bachis/category/uncategorized/?filter=comments - works
So right now I'm not using the rewrite endpoints and just adding query vars to the
end, but it would be great if the endpoints worked for cleaner url's.
Any ideas? I thought maybe the name 'filter' was causing an issue so I changed
it to 'blog-filter', flushed my permalinks and still had the issue.
@maxchirkov
Copy link

Don't you need to add new rewrite rule via "rewrite_rules_array" filter? Like this:
add_filter("rewrite_rules_array", "my_rewrite_rules");
function my_rewrite_rules($incoming){
$rules = array( 'my_regexp_url' => '?raw_url' );
return $rules + $incoming;
}

@billerickson
Copy link
Author

I haven't tried that yet, but I thought add_rewrite_endpoint would handle creating the rewrite rules. It works on standard posts, pages, and the main blog without adding any rewrite rules.

@maxchirkov
Copy link

You're probably correct there, I never used endpoint before and looking at the codex it seems should be handing rewriting as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment