WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do i filter posts in Home page. (6 posts)

  1. santosh.sahoo
    Member
    Posted 3 years ago #

    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 ) {
    
    	$ids=get_option("Fpost_list");
        if ( $query->is_home ) {
           	 $query->query_vars["post__in"]=$ids;
        }
    
        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.

  2. phoenix_decay
    Member
    Posted 3 years ago #

    Whats the domain for the website? I'll have to take alook at it so I can understand what your going for. :)

  3. santosh.sahoo
    Member
    Posted 3 years ago #

    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.

  4. phoenix_decay
    Member
    Posted 3 years ago #

    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.

  5. santosh.sahoo
    Member
    Posted 3 years ago #

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

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

    ??

  6. santosh.sahoo
    Member
    Posted 3 years ago #

    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 :'(

Topic Closed

This topic has been closed to new replies.

About this Topic