• Hi,

    I’m struggling with the following problem I’m trying to develop. Maybe it’s something small I’m overlooking, maybe it’s impossible all together. Not sure. Here goes…

    We’ve created a set of qr codes. Each qr code links to a url in the form of domain.com/?key=12345. The idea is that if the qr code is scanned, a browser window opens up with that domain; not a big issue so far.
    Now, those url’s don’t have existing pages related to them. Those pages should be generated ‘on the go’ and should use a custom build template. The idea here is that if the url parameter ‘key’ equals 12345, use custom template and populate it with data related to 12345. That key parameter could be any number: 12345, 52345, 14235, etc.

    Building custom templates and populate them with dynamic content (through WP ACF, api or whatever) isn’t a problem for me. The problem is how do I generate the pages the qr code should open up? And how do I grab the related content the key parameter refers to?

    I did google a lot for this and one thing that kept popping up was url-rewrites in combination with custom posttypes. Tried this, but didn’t seem to get it to work. At least not for the issue at hand.

    I hope the explanation of the issue is clear and someone could guide me in the right direction.

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

    (@bcworkz)

    You’ve pretty much described in general what any CMS system does. Take an arbitrary value and show related content. The devil is in the details. How do you relate the arbitrary value to content in the DB? You must do this somehow. In your example, 12345 could be a term ID, a term of some taxonomy. Categories, foobars, whatever. The term is assigned to post content, so you are asking WP to get all content with that term assigned. Content would be kept in the posts table. The usual posts can hold arbitrary content if you are not using them for blogging. Or you can create a new post type. The post type is just another data container you can use for any purpose.

    It’s up to you to figure out how that all works with your data. The mechanisms are in place, but it’s up to you to relate content to terms so WP can deliver what you want.

    Thread Starter floi13

    (@floi13)

    @bcworkz thanks for your reply.
    Haven’t thought of terms; perhaps that’s the way to go for me. If I understand you right it could be something like
    – I create a custom posttype
    – I create a custom taxonomy for that posttype

    I then create a template with a term field and if the id equals 12345, show the content related to that id.

    Am I correct so far?

    Moderator bcworkz

    (@bcworkz)

    Yes, I believe so, though the way your phrased the template logic gives me pause. Maybe I’m taking it too literally, but what you said in equivalent code would something like

    if ( $_GET['term-id'] == 12345 ) {
       $query = new WP_Query(['my_taxonomy'=> 12345,]);
       if ( $query->has_posts()) do_the_loop();
    }

    This of course only works for the ID 12345. You want it to work for any valid ID, as in:

    if ( isset( $_GET['term-id'])) {
       $query = new WP_Query(['my_taxonomy'=> $_GET['term-id'],]);
       if ( $query->has_posts()) do_the_loop();
    }

    I’m pretty sure the latter is what you would have done, but the former is literally what you said ??

    (the above code would not actually work, its purpose is only to illustrate logic)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Generate pages from url params’ is closed to new replies.