Forums

[resolved] Get pages with meta_key & meta_value (4 posts)

  1. Martin
    Member
    Posted 1 year ago #

    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;
    ?>
  2. keesiemeijer
    moderator
    Posted 1 year ago #

    try it with get posts:

    $pages = get_posts('meta_key=productfeatured&meta_value=yes&post_type=page');
  3. Martin
    Member
    Posted 1 year ago #

    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'); ?>

  4. Martin
    Member
    Posted 1 year ago #

    Thanks keesiemeijer - that worked perfectly, thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic