Forums

Get all pages with Custom Field Name/Value (5 posts)

  1. Onebrightlight
    Member
    Posted 3 years ago #

    I'm looking to add links to a section that link to attorneys who match a custom field name/value. In this case, it's a value of the meta_key being something like "tax_planning" and the meta_value being "on". How would I insert that into a link so that I return a series of all pages that have this combination?

    Thanks for your help!

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    Look to use the template tag, query_posts():

    query_posts('meta_key=tax_planning&meta_value=on&post_type=page');

  3. Onebrightlight
    Member
    Posted 3 years ago #

    Thanks for the help!
    When I put it into the place of the link however, the page ends up not loading, though no error message is given. It just seems to keep trying to access the page. Am I forming the link incorrectly?
    <a href="<?php query_posts('meta_key=tax_planning&amp;meta_value=on&amp;post_type=page'); ?>">Commercial Litigation &amp; Dispute Resolution</a>

  4. MichaelH
    Volunteer
    Posted 3 years ago #

    That query_posts will return a list of posts meeting that criteria. You will need to put that code, along with a loop, in the necessary template.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  5. Onebrightlight
    Member
    Posted 3 years ago #

    Right. I think I've got that here, but I could of course be wrong. I think it's set up in the loop currently this way:

    http://pastie.org/private/y9oaqffkjbqilsi3tglq

    Basically when I click the link, I'd like to generate a page that lists everyone matching these values. That or a dropdown box below the DL would work too.

    Sorry if I'm making this too confusing. The client ended up requesting these features MUCH after the fact.

Topic Closed

This topic has been closed to new replies.

About this Topic