Skip to main content

10 Useful WordPress Loop Hacks | Developer's Toolbox | Smashi...

Popularity Report

Total Popularity Score: 0

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Rank

Bookmark History

Saved by 32 people (-2 private), first by anonymouse user on 2009-06-10


Public Sticky notes

2. Use More Than One Loop On A Page, Without Printing Duplicate Posts

Highlighted by liishygo

2. Use More Than One Loop On A Page, Without Printing Duplicate Posts

Highlighted by liishygo

We only have to use the query_posts() function with the meta_key and meta_value parameters:

Highlighted by liishygo

4. Get Posts With A Specific Custom Field And Specific Value

Sm3 in 10 Useful WordPress Loop Hacks

The problem.
Because of the popularity of WordPress’ custom fields, you will often want to be able to output a list of posts with a specific custom field and specific value. While so simple for advanced WordPress users, beginners continue to ask me about this on my blogs. So, here’s the correct and easy way to achieve this.

The solution.
Not hard at all. We only have to use the query_posts() function with the meta_key and meta_value parameters:

1<?php query_posts('meta_key=review_type&meta_value=movie');  ?>
2<?php if (have_posts()) : ?>
3<?php while (have_posts()) : the_post(); ?>

Code explanation.
Definitely nothing hard here. To get only posts with a specific custom field and specific value, you have to use the query_posts() function with the meta_key and meta_value parameters. The meta_key value is the name of the desired custom field, and meta_value is the desired value.

Source

5. List Upcoming Posts

Highlighted by eliwagar