• Resolved Andrew Tegenkamp

    (@andrewteg)


    I’m writing a plugin that takes custom data tables from outside WordPress and puts the data in them on pages. I’m thinking either a page template or a [shortcode] would be the way to add this to a page, and open to suggestions there.

    Also, the data has about 1,000 different IDs, so I’d like to have a page or pages as site.com/page-title/100 should data for ID #100 and site.com/page-title/200 should show ID #200 and so on. Just site.com/page-title/ can show a list or search function.

    I’m a little unclear from the Rewrite API how to read the URL to get the ID, and also how not get a 404 on those subpages.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Templates are not the greatest solution for plugins. They’re really a theme thing, though they can be made to work from plugins. A custom shortcode or block gives users the ability to place content where they like in a post/page.

    For an external ID value, you’ll want to add your own query var for it using the “query_vars” filter. Then add a rewrite rule that captures the ID value in the URL and assigns it to your query var. The URL structure should have some static value, or WP will confuse it with a page break request. A structure like example.com/page-title/my-id/100/. Your rewrite rule regexp can then reliably match the “my-id” portion and rewrite accordingly.

    Your shortcode or block can then get the “my-id” value out of the main query’s query vars and use it as desired.

    Thread Starter Andrew Tegenkamp

    (@andrewteg)

    Thanks @bcworkz for that great explanation and info.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Plugin Using Rewrite for Detail Pages?’ is closed to new replies.