Support » Developing with WordPress » Display posts with datas of custom database table

  • agence24

    (@agence24)


    I think the title is not very explicit, but I don’t know how to name it…
    Well, I’m totally stuck on a question: To make it simple, I work on a site referencing places and their information. These datas are on a custom table, in my database. Currently, I display the name and a photo of these places on a WordPress page.

    The next step is the one I’m blocking completely: I would like us to click on these items, and the page of the place we clicked opens, displaying information available in my table. I thought about CPT, but the list of places is updated every night by a CRON task.

    My question is, how to display these pages, when they do not exist in the backoffice?

    Thank you so much !

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You can query custom tables by using the global $wpdb object. Once it returns the queried data, output it in whatever format you want. The code to do all of this should be placed on a custom page template. Add a new page based on this template so there is a permalink to use to access the data.

    One page with custom template could be used to handle all information about any given site by passing the site (by name or some sort of ID) as an URL argument. For example, in the brief listing for the site “foobar”, a link to more information could look something like httр://example.com/site-info/?site=foobar.
    Where the page with custom template’s slug is site-info. The template code can get the passed site name from $_GET['site'], query the table for foobar information, then display it.

Viewing 1 replies (of 1 total)
  • The topic ‘Display posts with datas of custom database table’ is closed to new replies.