[wp-hackers] Building a JSON API style plugin

John Blackbourn johnbillion+wp at gmail.com
Mon Nov 28 14:34:54 UTC 2011


On 28 November 2011 14:31, Tom Barrett <tcbarrett at gmail.com> wrote:
> Further experimentation shows that this works (functions.php):
>
> <?php
> $wp->add_query_var( 'ticket' );
> add_rewrite_rule( 'ticket/([0-9]+)/?$', 'index.php?ticket=$matches[1]',
> 'top' );
>
> add_action( 'template_redirect', 'get_ticket' );
> function get_ticket(){
>  $ticket = get_query_var( 'ticket' );
>  error_log( "ticket={$ticket}" );
>  return;
> }
> ?>
>
> Does anyone know which action hook this would be best placed in?

The init action should work fine for rewrite rules. You may want to
try the code in a separate plugin instead of functions.php, although
there should be no difference.


More information about the wp-hackers mailing list