What is appropriate flow for custom data from URL in WP_Query?

I think the WP function you are looking for is add_rewrite_tag. It aims to add custom GET params to your URL and include it automatically in query_vars.

For example, you can add the following to the init hook :

add_rewrite_tag('%person%','([^&]+)');

For a url like http://example.com?person=joe, the global $wp_query will have

$wp_query->query_vars['person'] = 'joe'

You can also add a rewrite rule to make the URL prettier, for example http://example.com/person/joe

add_rewrite_rule('^person/([^/]*)/?','index.php?person=$matches[1]','top');

See the Rewrite API for more information and examples.

Leave a Comment