Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am developing a theme for general release and there is a large content slideshow on the homepage.

I have included a checkbox meta box in the post edit screen that allows users to determine which posts are featured in the slideshow but I can't figure out exactly how to create a query for this.

The checkbox relates to a custom field called "slideshow"

Here is my slideshow code so far;

<div id="slides">
<div class="slides-container">

    <div class="slide-content">
        <a href="<?php the_permalink('');?>"><?php the_post_thumbnail('slideshow-thumb');?></a>
        <div class="slide-info">
            <h3><?php $category = get_the_category(); echo '<a href="'.get_category_link($category[0]->cat_ID).'">'.$category[0]->cat_name.'';?></a></h3>
            <h4><a href="<?php the_permalink('');?>"><?php the_title('');?></a></h4>
            <?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,70);?>
        </div><!--/.slide-info-->
    </div><!--/.slide-content-->

</div><!--/.slides-container-->

Any help would be greatly appreciated.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You can filter on meta values using query_posts() or a new WP_Query() for example:

query_posts( array(
    'meta_key' => 'slideshow', // the custom field key to check
    'meta_value' => '1',       // the value eg. 0 or 1
    'meta_compare' => '='      // check for equivalence
) );

// your loop goes here

wp_reset_query();

There is a lot more you can do with meta queries if you take a look in the codex including querying on multiple meta keys and values at the same time.

share|improve this answer
    
Perfect. I've actually used a meta query before, I have no idea why I didn't think of it. –  Dean Elliott Oct 26 '11 at 9:59
    
@dean-elliott one of those "can't see the wood for the trees" moments! –  sanchothefat Oct 28 '11 at 16:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.