{"id":17857865,"date":"2024-06-29T12:40:05","date_gmt":"2024-06-29T12:40:05","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/hiding-posts-from-main-page-archive-but-not-rss-feed\/"},"modified":"2024-06-29T12:40:05","modified_gmt":"2024-06-29T12:40:05","slug":"hiding-posts-from-main-page-archive-but-not-rss-feed","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/hiding-posts-from-main-page-archive-but-not-rss-feed\/","title":{"rendered":"Hiding posts from main page\/archive but not RSS feed"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I&#8217;m trying to hide certain posts (either by ID or category) from my site&#8217;s main post list, archive post list, and the custom search feature, -but- I need those posts to still show up in RSS feed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;ve tried multiple approaches from articles\/ChatGPT, but none have worked to hide the posts from the above locations. I&#8217;m stumped. It seems as if the add_action on pre_get_posts is just not working for some reason, but I&#8217;m not sure why.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below are a few of the example code snippets I&#8217;ve tried in functions.php:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function myFilter($query) {\n    if ($query-&gt;is_feed) {\n        $query-&gt;set('cat','-1'); \/\/Don't forget to change the category ID\n    }\nreturn $query;\n}\n\nadd_filter('pre_get_posts','myFilter');\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>function exclude_posts_from_homepage($query) {\n    if ($query-&gt;is_home() &amp;&amp; $query-&gt;is_main_query()) {\n        \/\/ Replace with the IDs of the posts you want to exclude from the homepage\n        $exclude_posts = array(2324,2325,2327); \/\/ Replace with actual post IDs\n        \n        \/\/ Exclude posts from the homepage\n        $query-&gt;set('post__not_in', $exclude_posts);\n    }\n}\nadd_action('pre_get_posts', 'exclude_posts_from_homepage', 1);<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-17857865","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17857865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17857865\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=17857865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}