Home › Forums › Support › Remove Specific Post From Blog Page This topic has 14 replies, 3 voices, and was last updated 1 year, 3 months ago by Ying. Viewing 15 posts - 1 through 15 (of 15 total) Author Posts June 20, 2022 at 9:06 am #2259252 Caitriona I am trying to remove a specific post from my blog page. How do I do it? June 20, 2022 at 9:23 am #2259273 DavidStaff Customer Support Hi there, try this PHP Snippet: function excludePostId($query) { $postIds = array( 66 ); if ( $query->is_home() && $query->is_main_query() ) { set_query_var('post__not_in', $postIds); } } add_action('pre_get_posts', 'excludePostId'); Change the 66 to the ID of the post you want to exclude. June 20, 2022 at 10:15 am #2259331 Caitriona Is there something missing in this code? I tried it by adding it to my Generatpress Child Theme and cleared the cache but I didn’t see any improvement. June 20, 2022 at 10:30 am #2259354 YingStaff Customer Support Hi Caitriona, What’s the code you are using? Have you changed the 66 to the IDs of the posts? June 20, 2022 at 10:41 am #2259365 Caitriona Hi, yes I did. Sent you a screenshot. June 20, 2022 at 11:16 am #2259391 YingStaff Customer Support The code looks right. I checked all 27 pages of your blog, I don’t see this post. June 20, 2022 at 11:21 am #2259398 Caitriona Did you try using the search bar? When I use the search bar I can see it. The search bar is in the top right when you click on Blog June 20, 2022 at 11:23 am #2259401 YingStaff Customer Support That’s the search result page, your original request is to remove the post from blog. So do you want to remove the post from the search result page as well? June 20, 2022 at 11:31 am #2259409 Caitriona Ah ok. I didn’t know there would be a difference. Yes, I would like it too, please. June 20, 2022 at 11:36 am #2259415 YingStaff Customer Support Then use this snippet instead: function excludePostId($query) { $postIds = array( 4986 ); if ( ($query->is_home() ||$query->is_search() ) && $query->is_main_query() ) { set_query_var('post__not_in', $postIds); } } add_action('pre_get_posts', 'excludePostId'); June 20, 2022 at 12:04 pm #2259437 Caitriona Will this code remove from blog and search results? I need it removed from both. Or will I just use both snippets? June 20, 2022 at 12:11 pm #2259438 Caitriona I have added it just now. June 20, 2022 at 12:26 pm #2259453 YingStaff Customer Support Only my snippet is needed, you can remove the old one. Just checked the search result page, it seems working well: https://www.screencast.com/t/IDEdVr9mjj June 20, 2022 at 12:39 pm #2259469 Caitriona Thank you, Ying ๐ June 21, 2022 at 1:41 pm #2260501 YingStaff Customer Support No problem ๐ Author Posts Viewing 15 posts - 1 through 15 (of 15 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In