WordPress.org

Forums

[resolved] Variable Conditional Tags? (5 posts)

  1. CowboyFrank
    Member
    Posted 5 years ago #

    Here's a challenge:
    I would like to make a page template that contains conditional tags which draw their data from a custom field. For example:

    • I have five different user groups - 1, 2, 3, 4 and 5.
    • Each user group has a distinct "Information" page.
    • Each Information page uses the Loop to display four different kinds of information - news, events, people, and places - specific to each group.
    • Each kind of information has their own post category.
    • Each User Group uses a Custom Field called "Group," and the value is equal to their name. (i.e. Group 1's value is "1")

    The template should include some code that looks at the Page and says, "On the Information Page for Group 1, there is a Custom Field 'Group' designation of '1'. So, where the conditional tag calls for News posts, I'll display any News post which also has the Custom Field Group designation of '1'." This way, I can use only one template, rather than having to make a separate template (and/or separate News, Events, etc. category) for each User Group. Plus, it makes it way easier to add (or subtract) additional user groups.

    Does this make sense, or am I making it more difficult than I need to? Please help!

  2. MichaelH
    Member
    Posted 5 years ago #

  3. CowboyFrank
    Member
    Posted 5 years ago #

    Michael,
    Thanks! your suggested code:
    query_posts('meta_key=city&meta_value='.$value_from_get_post_meta);
    has me on the right track, using the following code for my own specific purposes:
    <?php query_posts('category_name=region-leadership&meta_key=Region&meta_value='.$value_from_get_post_meta); ?>
    However, the last part...
    .$value_from_get_post_meta
    ...doesn't seem to be calling on the meta_value of the page it is creating. Rather, it returns all the posts that fit the first two requirements (category and meta_key). The page being created <i>does</i> have a custom field meta_key of Region with a corresponding meta_value. What code should I use to call that value? Thanks again for all your help!

  4. MichaelH
    Member
    Posted 5 years ago #

    Use get_post_meta to get that from your page.

    Related
    Custom Fields

  5. CowboyFrank
    Member
    Posted 5 years ago #

    Thank you so much for your guidance! With a little learning and experimentation, I got it working perfectly!

Topic Closed

This topic has been closed to new replies.

About this Topic