Forums

Page Template to Auto Create Pages for Custom Fields (1 post)

  1. mikejandreau
    Member
    Posted 10 months ago #

    Here's what I'm trying to do:

    I want to be able to generate (automatically) a page for a specific custom field, in this case "city". By "automatically", I mean based on the URL of the page.

    ie; http://www.domain.com/city/boston where "boston" would be the value of the custom field. The page would then output the correct posts that contain that listing.

    I found this code in the codex:

    $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wpostmeta.meta_key = 'city'
        AND wpostmeta.meta_value = 'XXXX'
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        AND wposts.post_date < NOW()
        ORDER BY wposts.post_date DESC
     ";

    Which does exactly what I want. However, I need the XXXX for the meta_value to come from the URL. Is here some way I can accomplish that without having to manually create a page for each city?

    My reasoning for wanting it automatic (like author listing pages) is that the content for this site will be user generated, and it could be time consuming to manually create a page template for every city and/or state.

    Any guidance would be greatly appreciated.

Reply

You must log in to post.

About this Topic