This would probably be best done using a custom WP_Query as opposed to a filter.
So say your site is about plants but you don’t want this custom archive to show posts where you have your plant custom taxonomy set to weeds:
$args = array(
'post_type' => 'post',
'tax_query' => array(
'taxonomy' => 'plants',
'field' => 'slug',
'terms' => 'weeds',
'operator' => 'NOT_IN',
),
);
$myArchive = new WP_Query($args);
So what this code is doing is creating a new query for posts looking at the slug for the taxonomy of plants and then grabbing them all except those with a slug name of weeds and then you can use the loop to display them however you want in the widget.
Just remember to use wp_reset_postdata() after the last post is displayed in your widget to reset $post back to the default query.
Related Posts:
- Archive Widget – Count only parent posts
- How can I modify the WordPress default widget output?
- How to hook into unregistering a widget instance?
- Prevent 404 when using pre_get_posts to filter an archive page
- Filter Widget Title Wrap
- Is it possible to remove the filter from 4.8 text widget?
- Anyway to edit the titlebar of WordPress Widgets in the Admin area?
- WordPress tag cloud add more links
- How to add a class to Tag cloud widget link?
- How to make a widget expand wider than the column width when editing its settings in the admin
- Multiple filters for wp_get_archive
- Warning: Missing argument 2 for widget_title filter
- Sorting a specific taxonomy by archive date using URL
- Add Bootstrap Classes to Recent Posts Widget
- include specific Pages to wp_list_pages with filter
- Shortcodes within the sidebar text/html widget: How to preserve the raw HTML output of the shortcode?
- I’ve set up an extra field for all the available widgets. How do I show it’s value in the front-end?
- Widget image reorganize layout
- How can I change the button text of a custom widget?
- WordPress Tag Cloud Filter Prevents Widget HTML from loading
- How can I add a prefix to titles displayed in sidebar using function.php?
- URL to filter posts by post meta similar to shop/?product_cat=”painting”
- Output dynamic_sidebar_params in wp_head
- Hide a specific post from Archive Feed
- Post filter Month dropdown at front-end like wordpress backend
- Filter on widget-title does not work with custom links
- How to use apply_filters(‘get_calendar’) to change get_calendar() output?
- Filter widget_pages_args not working in Pages Widget
- Woocommerce price filter widget always shows max price of most expensive product in the whole shop
- Load More : Admin Ajax 400 Bad request, returning 0
- Trouble understanding apply_filters()
- How would one modify the filtering Gutenberg applies to pasted content?
- Gutenberg: Is there a way to know if current block is inside InnerBlocks?
- How to reorder billing fields in WooCommerce Checkout template? [closed]
- How to add a custom CSS class to core blocks in Gutenberg editor?
- Filter translations (gettext strings) on specific admin pages
- Is it possible to use object in add_action?
- Filter hook before create order WooCommerce
- How to auto-translate custom user roles?
- add_filter for specific pages
- How to add attribute to output with wp_video_shortcode add_filter
- How to override the email function by using filters? [closed]
- Remove WPML’s home_url filter
- Change default settings used by gallery shortcode
- PHP5, Inheritance, Singleton – action & filter hook limitations
- Please explain me what the do_action does
- Add ‘if exists’ to filter
- How to get current action?
- How to check if “media_send_to_editor” is audio?
- Changing Order of Filters
- Please help me through this example with a filter to understand how they work
- how to change appearence of the content of default post list columns?
- Filter custom post types in archive
- Use safety filters even if after applied intval?
- How can I filter block registration based on post-type? (Block alignment settings)
- wp_insert_post_data filter not working correctly after upgrade to WordPress 5
- Modify site URL via functions.php of a theme
- Yoast SEO hooks overriding themselves
- Passing variable from child theme to parent theme
- Question about how do wordpress filters/actions work
- How to change the order (priority) of registered filters (or actions) (e.g. for the_content)?
- How to take options from form fields and turn them in to links?
- How add a group by to the query used by the media library?
- How to properly modify WP Vary or any existing headers?
- Filters on Login Page
- How to filter link?
- Conditional does not work with add_filter
- Pass debug_backtrace() in WordPress filter
- How to edit embed filter for youtube video to allow responsive full width layout
- Remove get_template_part() from custom theme
- How to access page variable inside action hook
- Shorten the title length
- Problem with Class, Filters and Callbacks
- Renaming wordpress login and get new password button
- Using filter in the widget causes fatal error
- preg_match() not working with post content
- Search a title word through query_posts (not the exact match)
- Parse a shortcode differently based on on what it’s nested in
- Elementor Image Hover + Filter Grid [closed]
- Is possible register two archive pages for single custom post type?
- How to redirect template_directory to subdomain relativ url?
- Scanning for custom embed and prefetching
- How to exclude or include categories in wp rest API without query parameters?
- Remove and replace woocommerce add to cart button [closed]
- Replace a specific URL on all apperances on the Website (Maybe a filter?)
- how to use apply filter for Class?
- Modify WordPress search behaviour in backend?
- Re-order search results with posts_orderby filter and post meta value
- ‘the_content’ Filter delivers empty string with lengh (608)
- How do I disable the warning “The backup of this post in your browser is different from the version below”?
- Change url to posts if they have custom tax only
- How to get to the date of the uploaded file
- Publish button inside custom field group
- Can’t get content of all (19) posts – Incomplete Chunked Encoding
- Customize register form page with add_action or apply_filter
- How to separate a specific page’s comments from other comments
- Woocommerce: Only one review per verified buyer [closed]
- str_replace css meta tag?
- This code works, but breaks the media uploader. How do I integrate it in a way that won’t?
- How to add placeholder into comment form textarea?