WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Query_posts exclude page (5 posts)

  1. treelovinhippie
    Member
    Posted 4 years ago #

    Hi

    I'm running this code to list out pages (need to for a particular implementation):

    query_posts('post_type=page')

    However I'd like to exclude the pages named "logo" and "about" from the query loop.

    How do I add that into the query?

    ... also, how would I get the query to display two particular pages, e.g:

    query_posts('post_type=page&pagename=logo,about')

    cheers

  2. MichaelH
    Member
    Posted 4 years ago #

    Figure out the page ids for those two pages and use:

    //replace the 3,8 with your page ids
    $args=array(
      'post__not_in' => array(3,8),
      'post_type' => 'page',
      'post_status' => 'publish',
    );
    query_posts($args);

    Related:
    How do I determine a Post, Page, Category, Tag, Link, Link Category, or User ID?

  3. treelovinhippie
    Member
    Posted 4 years ago #

    Thanks, though is there any way to do it based off pagename/slugs?

  4. MichaelH
    Member
    Posted 4 years ago #

  5. treelovinhippie
    Member
    Posted 4 years ago #

    Awesome, works a treat! ... thankyou

    $pagelogo = get_page_by_title('Logo');
    $pageabout = get_page_by_title('About');
    $args=array(
      'post__not_in' => array($pagelogo->ID,$pageabout->ID),
      'post_type' => 'page',
      'post_status' => 'publish',
    );

Topic Closed

This topic has been closed to new replies.

About this Topic