Exclude page from loop results

You need the WP_Query documentation. WP_Query is very powerful, and you can do a lot with it 🙂

In your case, I don’t think exclude is a valid parameter. What you’re probably looking for is this:

$query->set( 'post__not_in', array( 34 ) );

Here’s the Post & Page Parameters section of the documentation, which covers this and the other parameters you can use.

(Incidentally, the other one you tried, category__not_in, will only exclude posts from category ID 34, not posts/pages with the specific ID 34)


By the way, you should also add an !is_admin() check to your function, otherwise you might find that this page starts to get excluded from display in the admin area as well.