Support » Fixing WordPress » How do i filter posts in Home page.

  • Resolved santosh.sahoo


    I want to display only some specified posts in the home page , instead of all posts.

    I have the id of all the post that i want in the home page.

    How do i do it with wp_query or query_post(); ?

    By using the following code , i am getting the result but the gallery does not comes in the posts.
    Have a look.

    function exclude_category( $query ) {
        if ( $query->is_home ) {
        return $query;
    add_filter( 'pre_get_posts', 'exclude_category' );

    The above code works , but i cannot understand why the gallery doesnt shows up.

    Any correction or suggestion would be wonderful..

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Whats the domain for the website? I’ll have to take alook at it so I can understand what your going for. 🙂

    i’m working on a local server…

    no external server to show u.

    Anyways.. i’ll explain it wait an example.

    Suppose there are 10 posts with id 1,2,3 ….10

    normally in home page all the posts will appear.
    but i want only posts with id 2,6,7 to in home page.

    how do i do it without hand coding in the theme files.

    The easiest way would be to set up a new category called “homepage” or what ever you want.

    Add any posts you’d like on your home page to that category.

    Then the query would be:

    query_posts( array ( ‘category_name’ => ‘The Category Name’, ‘posts_per_page’ => -1 ) );

    That would bring back all posts from that category.

    that could be done….but where do i use that function…??

    in the filter callback fn:
    add_filter( ‘pre_get_posts’, ‘exclude_category’ );


    what action hook should i use to run that function before the loop….

    “loop_start” wont work…

    and i dont want to write in the theme files :'(

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do i filter posts in Home page.’ is closed to new replies.