Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #116220
    MohAnghabo
    Participant

    I am attempting to exclude all sticky posts from my home.php page in Adventurous theme. I have specified a category to be shown on the home page. When I stick any post, it appears above the category posts – which is normal.

    What I want is not to show the sticky posts in the home page. I tried this code in home.php $the_query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) ); but it removes the front page category’s posts.

    How can I exclude the sticky posts from Home.php??!

    #116239
    Mahesh
    Keymaster

    @mohanghabo: For this, you’ll need to create a child theme. You can find more details on creating child theme HERE. Then in your child theme’s functions.php, add the following codes:

    add_action( 'pre_get_posts', 'adventurous_child_ignore_sticky' );
    function adventurous_child_ignore_sticky( $query ) {
        if ($query->is_main_query() && $query->is_home()) 
        {
            $query->set( 'ignore_sticky_posts', 1 );
        }
    }

    Regards,
    Mahesh

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Exclude sticky posts from Home.php’ is closed to new replies.