• I have band profile pages and a custom field for each page with their up coming gigs.

    For the front page of the site I want to pull a feed of just the bands that currently have upcoming gigs entered in their custom field.

    I’ve tried a bazillion different tutorials and things listed in the codex, but nothing seems to be working. Any ideas? Thank you ahead of time, I appreciate any help.

Viewing 8 replies - 1 through 8 (of 8 total)
  • i dont if you exists ready function for this. but you can query posts directly from database

    first check ids of posts which has meta key:

    “SELECT post_id FROM ” . $wpdb->prefix . “postmeta WHERE meta_key = ‘your meta key here'”

    then query posts with those ids which you selected above

    Thread Starter alanchrishughes

    (@alanchrishughes)

    I’ve tried quite a few variations from that codex page and other alchymth, but I must be missing something still. I’ve tried

    <?php query_posts('post_type=page&meta_key=gigONE'); ?>
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
    THREE
    <div class="BandListItem">
    
    <?php the_title(); ?>
    
    <?php meta('gigONE'); ?>
    
    </div> 
    
    <?php endwhile; ?>
    
    <?php endif; ?>
    Thread Starter alanchrishughes

    (@alanchrishughes)

    <?php query_posts('meta_key=review_type&meta_value=gigONE');  ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
    TWO
    <div class="BandListItem">
    
    <?php the_title(); ?>
    
    <?php meta('gigONE'); ?>
    
    </div> 
    
    <?php endwhile; ?>
    
    <?php endif; ?>
    Thread Starter alanchrishughes

    (@alanchrishughes)

    <div class="AlphaBandListContainer">
    ONE
    
    <?php $loop = new WP_Query( array( 'post_type' => 'band', 'orderby' => 'title', 'order' => 'asc', 'posts_per_page' => '10', true ) ); ?>
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    <div class="BandListItem">
    
    <?php the_title(); ?>
    
    <?php meta('gigONE'); ?>
    
    </div>  
    
    <?php endwhile; ?>
    
    </div>
    Thread Starter alanchrishughes

    (@alanchrishughes)

    <?php query_posts('post_type=page&meta_key=gigONE'); ?>
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    <div class="BandListItem">
    
    <?php the_title(); ?>
    
    <?php meta('gigONE'); ?>
    
    </div><!-- BandListItem -->
    
    <?php endwhile; ?>

    i guess, the output is ’empty’ with all these attempts?

    if you are not clear if you have post_type=page or post_type=band, try with post_type=any:

    <?php query_posts('post_type=any&meta_key=gigONE'); ?>

    Thread Starter alanchrishughes

    (@alanchrishughes)

    These results have either empty or they bring back everything.

    They are pages, not posts, and the custom field key is gigONE. So I’m not entirely sure when I should use one or the other in the code.

    I’m not sure if I made it clear in my original post, but I am only trying to pull pages that have something entered in this custom field, so I am thinking I need to something to specify that also, something to say pull pages if this meta key (gigOne) exists and only if there is a value entered.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Get Posts That Have A Specific Custom Field Key’ is closed to new replies.