• Resolved Martin

    (@martinlucas)


    I’ve grabbed the code from this previous support post; http://wordpress.org/support/topic/use-the-post-image-to-wp_list_pages?replies=9#post-1386992 and tweaked it ever so slightly to only show the pages where a custom field equals a certain value, but it doesn’t work.

    I’ve been round and round and simplified the code as much as possible – but still nothing. Can anyone tell me if there’s something wrong with the get_pages code here, it works fine if I pull in pages without mentioning the meta_key / value.

    <?php
    
    $pages = get_pages('meta_key=productfeatured&meta_value=yes');
    
    $output = '';
    
    foreach($pages as $value){
    
    	$thumb = get_the_post_thumbnail( $value->ID, array(175,175), $attr = '' );
    	$output .= "<li>";
    	$output .= "<a href='" . $value->post_name . "' >" . $thumb . "</a><br />";
    	$output .= "<a href='" . $value->post_name . "' >" .  $value->post_title . "</a>";
    	$output .= "</li>";
    } 
    
    echo $output;
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    try it with get posts:

    $pages = get_posts('meta_key=productfeatured&meta_value=yes&post_type=page');

    Thread Starter Martin

    (@martinlucas)

    To add more confusion, this code — replacing the above code — works fine.

    <?php wp_list_pages('title_li=&meta_key=productfeatured&meta_value=yes&number=3'); ?>

    Thread Starter Martin

    (@martinlucas)

    Thanks keesiemeijer – that worked perfectly, thanks so much!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get pages with meta_key & meta_value’ is closed to new replies.