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.
Related Posts:
- Using the Loop to show all levels of subpages under a parent page? Halfway there
- Child Pages Loop
- Get post by page name or slug
- Loop that displays PARENT PAGE & CHILD PAGE & outputs GRANDCHILD PAGE title and content
- Display subpages under parent page as a list within a loop
- Is including the loop necessary for page.php? [duplicate]
- Identify the page being shown while in The Loop
- If Loop has odd number of posts on last page Custom style for last post in it
- single page site with subpages
- How to loop through ALL pages?
- Loop and Page template : my WP_query don’t take args
- Create a loop that gets pages with their template
- Display content of page template (get_page)
- Loop after page content
- wp alchemy multiple image uploader output images to template
- Next Posts Prev Posts for Standard post format only
- Get Page content to displayin Bootstrap Modal
- How do I make a variable available inside partials?
- Exclude page name from loop
- Stepping through a foreach loop – adding +1 to the end of it so next time it loops it starts on item 2
- Include multiple page ids in loop
- Get post offset/posts page offset in single post page (outside the loop)
- First archive page with a few posts
- Tags on page (not post) returns nothing – why? Improved clarified question!
- Exclude category from get_the_category
- Print the whole page?
- WP_Query is only looping home page, not pages
- How do i create a list-posts-page?
- Exclude current post ID from loop in sidepbar.php
- WordPress: query pages except remove one page
- Only Show Excerpt After First 3 Posts
- Archive: Lists itself
- is it bad to copy the loop for a template?
- Get top Page IDs from menu and cycle through their child pages on a scroller
- Search – Check if post is a page on search page
- Structure and Display Content from Multiple Pages on Single Page
- Making a specific page wordpress compatable that is not index
- Default Template infinite loop of Title
- Have multiple loops on a page appear after/between page content
- get_template_part() to render single page Theme
- Exclude Authors based off date of last post
- get_page() unlike Loop returns the post content without html tags. How can I fix this?
- Jquery Slider for profile template
- Get excerpt using get_the_excerpt outside a loop
- wp_list_categories: get latest featured_image of category
- WordPress Alphabetical Glossary close div in loop
- Listing all posts from current category on page
- How to make multiple Column in archive Page?
- category__not_in — anyway to use category name instead of id?
- Filtering posts by multiple taxonomies
- Why do I get `Call to a member function have_posts() on a non-object `? [closed]
- Help with Changing loop.php?
- Differentiate between posts and pages in search results
- Category Ajax call
- Change front-page layout after x amount of posts ( while in the same loop)
- Transient loop issue
- popular post weekly and monthly
- How can i use the same template file with a widget and category loop?
- WordPress Loop inside Loop?
- angularjs not displaying all posts
- query_posts() vs get_posts() multiple loops [duplicate]
- ACF custom field in [closed]
- Split wordpress loop to multiple layouts
- Update status of all posts in a category
- is_active-sidebar loop
- Unable to change the “Read more” text inside the_excerpt
- Conditional: IF current user has NOT commented on current post (not including post author)
- Change post order by meta key, per post basis
- Query Nopaging action not having effect
- How do i find and restore a sidebar that i accidentally deleted? [closed]
- Posts not showing
- CPT while loop not working
- Problem with Front-Page.php loading recent posts
- Comments_template doesn’t work
- Get markup for post without loading into the template
- Where to add offset?
- How to synchronize The Loop with the max post per page?
- How to add a byline to all the pages?
- Displaying member join date on page
- Ascending order has strange effects on wordpress loop
- get post images to link to external sources
- Set depth of pages to fetch
- Skip latest 3 posts from loop
- How to execute a user loop with shortcode
- Custom loop not working in singular.php, working in other pages
- Loop Posts Outside of WordPress Installation
- Strange problem with wp_get_attachment_image_src database (db) query count
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Issue in If else condition [closed]
- display only parent replies count in index.php
- using the loop on a page
- Redirecting posts in WordPress to a specific page
- Eliminate duplicates in a foreach loop [closed]
- Tag custom loop show posts
- While loop inside another while loop
- loop mix my child-category and parent-category
- Fix html inside a for loop [closed]
- Insert multiple custom components after x-number of posts
- Use Base-URL with Query-Loop