Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #577809

    I have one post that I would like to exclude from the blog archive. I created a unique post category for it and tried adding code I found online to my template-archives.php file, with no success.

    I have no experience in programming PHP pages, so any suggestions should include code, if necessary, that I can copy and paste into my site.

    Thanks!

    #577814

    Hi ferriscreative!

    Please add following code to Functions.php file in Appearance > Editor

    function avia_remove_post_from_category( $query ) {
        if ( is_admin() || ! $query->is_main_query() )
            return;
    
        if ( $query->is_archive() ) {
            $query->set( 'post__not_in', array( 4139 ) );
        }
    }
    add_action( 'pre_get_posts', 'avia_remove_post_from_category', 1 );

    Best regards,
    Yigit

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.