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
- How to remove a filter that is an anonymous object?
- How to add a custom CSS class to core blocks in Gutenberg editor?
- No filter of code on switch from html to visual editor, how?
- How to modify posts_where filter only for the search query
- How to wrap oEmbed-embedded video in DIV tags inside the_content?
- How to add filter with 2 args?
- How to auto-translate custom user roles?
- Adding revision support to WooCommerce product content
- Changing text within the Block Editor
- Search content for shortcodes and get parameters
- Change default settings used by gallery shortcode
- Please explain me what the do_action does
- How Can I Have A URL Changed Based on the Originating URL?
- Is it possible to Hook/Filters Attachment Creation?
- Apply the_title filter to post titles AND backend auto social-sharing plugin, but not nav menu
- How to hook some Unicode texts into calendar widget safely?
- how to remove filter from wordpress shortcode output
- Change email from and display name with a filter action
- Please help me through this example with a filter to understand how they work
- Filter custom post types in archive
- wp_insert_post_data filter not working correctly after upgrade to WordPress 5
- Yoast SEO hooks overriding themselves
- Question about how do wordpress filters/actions work
- How to center oEmbedded content
- Add Sortable Column For All Post Types
- How to take options from form fields and turn them in to links?
- How to change the order of HTML output of a core block?
- When to use add_action when registering/enqueuing scripts
- Is it possible to use multiple spaces in title?
- add_filter(allowed_block_types) -> adding core/paragraph bugs Gutenberg editor
- How to remove medium size class in gravity form for input tag?
- Filter out comments with certain meta key/s in the admin backend
- WordPress custom admin notice still displays after wp_insert_post_data validation
- Custom wp_query time filter on meta_value
- get post id within add_filter()
- Media upload default title from file name
- Admin post list – adding an option to the date filter dropdown
- Use of comment_reply_link_args filter
- Error using wp_mail inside custom function
- Add/remove CRON action depending on variable
- Admin: how to make a custom list filter button send GET queryvars
- Filter authors on meta value
- Override email_exists function
- Access post ID in “content_save_pre”
- arguments for comment_notification_text filter
- Gallery stripped from excerpt of post
- Add_filter rel=”prettyphoto” to WP3.4.1
- exclude certain categories form archive widget
- How can i filter wordpress users by custom feild?
- How to filter the source URL of all images on every page
- auth_redirect() doesn’t send users to the page where they orginally tried to acces
- How to redirect a unique link based on login status
- Is it possible to assign a css id to a row in plugins list table?
- How to bridge the gap between dynamic back-end data and front-end output?
- How to loop year & month condition together to filter correctly via AJAX?
- How do I isolate the reason a wordpress filter is not running?
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- Modify Default URL for /wp-includes/js/wp-emoji.js?ver=4.6.1
- List all image sizes still getting disabled sizes
- wp_editor customization
- What problems could happen if I replaced add_filter and add_action with the function calling
- posts_results filter function memory errors
- Adding to an array & passing it through do_action/apply_filters
- Activate short codes for all post queries?
- Save something to global var in add_filter
- Loading a sidebar on an Ajax call
- the_excerpt() does not work with has_excerpt()?
- Wrapping Featured Image on Add/Edit Page in div?
- how to localize the number of wordpress post views?
- How do you disable the verification process of user email changes?
- Modify the third (context) parameter in a filter?
- Limit total tags in the_content