WordPress.org

Ready to get started?Download WordPress

Forums

Display posts and pages if custom field is present (2 posts)

  1. ludderz
    Member
    Posted 4 years ago #

    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~

  2. ludderz
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.