I have created a plugin that creates a table in the database and allows users to add an Item to the table. I would like each item to also create a page for its self so that when the items are listed I can have each one link to there individual pages. Anyone know the proper way of doing this?


You can use wp_insert_post to insert a physical page, though I would suggest creating one page for the plugin and then using a rewrite rule to give all of your items a URL with that single page as the base.


quick rewrite example with added query var:

function wpa55546_rewrites(){
    $page_slug = 'your-page';

    // urls will be in the form
    // /your-page/42/

        $page_slug . '/([0-9]+)/?$',
        'index.php?pagename=' . $page_slug . '&my_id=$matches[1]',
add_action( 'init', 'wpa55546_rewrites' );

function wpa55546_query_vars( $query_vars ){
    $query_vars[] = 'my_id';
    return $query_vars;
add_filter( 'query_vars', 'wpa55546_query_vars' );

then in the template you'll have access to the value of your query var:

echo get_query_var( 'my_id' );

you'll also have to flush rewrite rules at the appropriate time.

  • could you give or link an example? Not sure what you mean about a "rewrite rule". You mean I create a page, then call the tables I want displayed on that page? Jun 17 '12 at 18:37
  • @KirillFuchs - see edit
    – Milo
    Jun 17 '12 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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