is there a way to set the order of posts via the url?
/orderby/date/order/desc/
i have tried several things with add_rewrite_rule whiteout success.
add_action( 'init', 'wpse13483_init' );
function wpse13483_init()
{
add_rewrite_rule( 'category/(.+?)/orderby/([^/]+)/order/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?category_name=$matches[1]&paged=$matches[5]&orderby=$matches[2]&order=$matches[3]', 'top' );
}
best, Dan.
adding this in the functions.php file works. Just remember to re-save your permalinks & empty the cache a few times to see the changes.
Creating URL rewrite rules is something entirely different from using URL query variables to sort the Loop query.
I would suggest tackling the latter, before worrying about the former.
First, you need to register your URL query variables, e.g. (in
functions.php
):So, now that you’ve registered your query vars, use them to modify the default Loop query.
First, prepare the query variables, e.g. (in the appropriate template files):
Now, use the query variables to modify the loop. First, set up your custom argument array:
Now, merge your custom argument array with the default loop query args:
Note: you’ll have to determine exactly how you’re applying the URL query strings. This code just uses the query strings once they’re in place.