Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to use the plus sign instead of the dash as the word delimiter in the url? And if so, how exactly would that be done?

e.g.: www.example.com/some-title/ becomes www.example.com/some+title/

Of course, ideally it would have to work with posts, pages and custom posts.

share|improve this question
3  
Is there any particular reason you want this done? It doesn't seem like it would have many benefits and it would be a fairly complicated change to make. – John P Bloch Apr 12 '11 at 19:21

1 Answer

Mark Jaquith uses "+" as the search query string delimiter in his Nice Search Plugin. Here's what he does:

function cws_nice_search_redirect() {
    if ( is_search() && strpos( $_SERVER['REQUEST_URI'], '/wp-admin/' ) === false && strpos( $_SERVER['REQUEST_URI'], '/search/' ) === false ) {
        wp_redirect( home_url( '/search/' . str_replace( array( ' ', '%20' ),  array( '+', '+' ), get_query_var( 's' ) ) ) );
        exit();
    }
}

Perhaps it may be of some use for reference?

share|improve this answer
Yeah, but + changes to a space when it's run through urldecode(), which WP does when matching against rewrite rules. You'd need to make sure you're checking against the correct slug in WP_Query, as well as modifying the permalink output, and maybe even filtering on redirect_canonical. – John P Bloch Apr 12 '11 at 19:24
Doesn't Mark's code run after URL rewrites are applied? (mod_rewrite is all still a bit of a mystery to me) – Chip Bennett Apr 12 '11 at 19:49
Yes, but spaces in searches are ok. If you have a space in the slug you look up, it won't match what's in the database. – John P Bloch Apr 12 '11 at 20:27
Sorry, to answer your question, I don't know when his code runs, but it redirects the page request to use the plus signs, so you get a fresh load starting with plus signs. – John P Bloch Apr 12 '11 at 20:28

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.