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?
- How to fix pagination for custom loops?
- Jquery Slider for profile template
- Counting the posts of a custom WordPress loop (WP_Query)?
- if ( is_home() && ! is_front_page() )
- Get excerpt using get_the_excerpt outside a loop
- How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
- Get post content from outside the loop
- Why should I put if(have_posts()), is while(have_posts()) not enough?
- Getting only direct child pages in WordPress with get_pages
- Display featured products through custom loop in woocommerce on template page
- Split Content and Gallery
- How to get Author ID outside the loop
- How can i display the content in plaintext
- How to check if I’m on the last page of posts?
- Redirect loop when trying to login to /wp-admin/ [duplicate]
- How to split a loop into multiple columns
- Is it necessary to reset the query after using get_posts()?
- Is there any difference between the_title() and echo get_the_title()?
- AJAX with loop filtering categories
- Do I need to use The Loop on pages?
- Remove the Homepage Query
- remove tags from the_content
- the_title() shows title of the first post instead of the page title?
- How to force excerpts / teasers in the loop
- Retrieve each widget separately from a sidebar
- Why am I being limited to ten posts on a custom loop?
- Should I use loop in the single.php file?
- A search for ‘0’ returns results
- Exclude the category from the WordPress loop
- Why do themes rely on “The Loop”?
- How to return loop contents
- Skipping first 3 posts in wp query
- Cleanest Way to Select Every Second Element in a Loop?
- Insert image or ad script after 3 posts using the loop
- Get date of last update outside of loop
- Pagination not working on home page
- How to place comments_template(); outside the loop?
- Multiple Loops Homepage?
- How to Change Loop to Order Posts by Views (using wp-postviews plugin)
- how to upload image using wp_handle_upload
- Avoiding using a loop to access a single post
- How to get the first image gallery of a product in woocommerce in a loop
- save_post + insert_post = infinite loop
- Loop.php vs looping inside template file
- Get ID of a page containing secondary loop in content
- Custom Loop and Infinite Scroll
- is_home, and is_front_page conditional problem
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- the_content and wp_link_pages
- Adding ‘current_post_item’ class to current post in the loop
- How do I get the attributes of a short code from a post?
- How can I custom order the results from wp_list_categories?
- ACF Repeater loops and resets – where is the reset_rows() documentation? [closed]
- WooCommerce Product Page Loop – Output All Product Thumbnails
- Why do I need to use The Loop on pages (inside page.php etc)?
- wp-admin redirecting to https, denying login
- Endless loop with wp_insert_post and wp_update_post