Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using WP rewrite rules for my custem arguments,
But when I am trying to generate permalink like this:

add_query_arg(array(
    'type' => 'foo',
    'paged' => 2,
),get_permalink($id)) ;

It returns still:

mysite.com/products/?type=foo&paged=2

But I need to turn it into this:

mysite.com/products/foo/2

Rewrite rules work perfectly, but "add_query_arg"..

How to solve?

share|improve this question
    
add_query_arg is for adding query string arguments, not for generating pretty permalinks. what context are you using this in exactly? have you already added your type query var and added a rewrite rule to handle incoming requests via add_rewrite_rule? –  Milo Feb 6 '13 at 0:30
    
@Milo I added a few rules via "generate_rewrite_rules" action –  Digerkam Feb 6 '13 at 0:38
add comment

1 Answer

up vote 0 down vote accepted

I'm affraid this "nasty" solution would be the most effective than trying to write some cool function that will translate your permalinks into pretty permalinks:

$permalink = rtrim( get_permalink( $id ), '/' ) . '/foo' . '/2';

The rtrim part (removing trailing slash) is just for to be sure there are not going to be two slashes on the end of the first part of your new pretty permalink.

share|improve this answer
    
The simple is the golden, you are right.. Sometimes it is effective doing it manually than building a framework in a framework :) –  Digerkam Feb 6 '13 at 21:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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