Support

Account

Home Forums General Issues Using meta_value with query_posts

Solved

Using meta_value with query_posts

  • I have a custom post type called Projects and I want to make a query depending on which radio button they’ve selected (“Architecture”, “Construction” or “Design”). In this case, let’s use Construction –

    <?php query_posts(array(‘post_type’ => ‘project’, ‘key’ => ‘project_label’, ‘value’ => ‘Construction’)); while (have_posts()) { the_post(); ?>

    But instead of just displaying Construction, it displays all Projects. Here’s how it looks in the admin –

    http://d.pr/i/nOmG

    Thanks! I love this plugin.

  • Hi @cutout

    I think you have used the wrong ‘value’. Instead of ‘Construction’, shouldn’t it be ‘construction’?

  • Thanks Elliot. I changed to lowercase, but it’s still displaying all projects, instead of filtering for construction. Any ideas for writing the query differently?

  • Hmm, looks like meta_key worked, rather than key…

  • Hi @cutout

    Yep, it’s always important to double check the docs!

    Cheers
    E

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Using meta_value with query_posts’ is closed to new replies.