WordPress.org

Support

Support » How-To and Troubleshooting » Display posts and pages if custom field is present

Display posts and pages if custom field is present

  • Heya all

    Ive been playing with some code i found on the forums that displays and links to posts if they have a custom field set. I am trying to acheive the same thing however i would like the list to include pages aswell. Im not to sure how to go about this though, can anyone help? The code i currently have is below, its a straight lift from another thread i found.

    <?php
      $postslist = get_posts('numberposts=-1&order=ASC&orderby=title&meta_key=restlist');
     foreach ($postslist as $post) :
    $customPostID = get_post_custom($post->ID);
    if(isset($customPostID['restlist'])) :
        setup_postdata($post);
    echo '<li><a href="' . get_permalink() . '">' . $customPostID['restlist'] . '</a></li>';
    endif;
    endforeach;
    ?>
    </ul>

    Any help will be much apreciated.

    Ludz~

Viewing 1 replies (of 1 total)
  • Missed the opening <ul> to the code, not that it makes a vast difference just letting anyone know if they were going to play with the code.

Viewing 1 replies (of 1 total)
  • The topic ‘Display posts and pages if custom field is present’ is closed to new replies.