I haven’t tested this, but I found a sample that was close. I have modified it to be similar to what you want. I’m not sure it is 100%, but it should get you really close:
add_action('pre_get_posts','wpse_filter_parents_only');
function wpse_filter_parents_only($query){
if (!is_admin() && is_category('26')){
$query->set('post_parent',0);
}
return $query;
}
This should update what WP_Query retrieves from the database, and only for category 26. If you need this to affect multiple categories, stuff them into an array and insert the array like this: is_category($cats)
.
Hope this helps!
Related Posts:
- Filter WordPress Archive Widget to exclude posts with specific custom taxonomy term id
- 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 hook a filter to catch get_post_meta when alternate a custom field output?
- Changing JPEG compression depending on image size
- How to add headers to outgoing email?
- Advanced Custom Fields and Yoast SEO keyword analysis [closed]
- Insert Custom HTML After Shortcode
- Is there a way to add another row to the tinyMCE kitchen sink toggle?
- Remove description from on Home
- add_filter to youtube embeds?
- How can I detect if a user changes their password?
- SSL certificate for the host could not be verified
- Store source permalink on XMLRPC calls
- How to limit the pages displayed for choosing parent page on page attribute’s menu?
- Programmatically Add Font-Awesome Icons to Category Widget
- What is the filter hook for custom fields content?
- Filter keywords from search query
- Add class to woocommerce checkout body based on filter [closed]
- changing variable through filters or action hooks
- filter the_title problem in nav
- Changing Gutenberg / WP block editor width only on pages, not posts or other taxonomies
- How to replace any occurence of Gravatars with a local placeholder image?
- Ignore dots when searching in the media library?
- How To Get User Data in Callback Function for pre_user_nicename?
- What’s the best way to split admin-only functionality in the theme’s functions.php file?
- Which built-in WordPress files are safe to edit?
- Why won’t my preg_replace work with content_save_pre?
- How do I target a single page to modify the comment form of only that page?
- How Does comment_author Filter Work?
- Add ‘data-text’ attribute to TagCloud HTML
- Contact Form 7 filter similar to preprocess_comment [closed]
- Walker_Nav_Menu doesn’t work in wp_page_menu_args filter
- get_posts() and filters
- upload_files cap to not loggen in users – add_cap to not logged in users
- How do I add a checkmark to my-sites save settings hook
- How to filter backend post list showing only posts having a shortcode
- Add Lightbox To WordPress Native Gallery
- How do I override the_excerpt so that it will display full content?
- Get current user data
- get_post() containing gallery is outputting an unmatched closing div at the end of the content
- How do I hook my function to run only after submitting login form
- How to write a filter to remove a form field (WordPress) [closed]
- Why doesn’t this function work when I know that the IP Address is “true”?
- Modify existing plugin function with add_filter
- Map plugin with proximity search compatible with Buddypress
- Removing URL and adding container around image in the featured image metabox
- Email Obfuscation: Is antispambot() Acceptable? [closed]
- What are the steps + prerequisites for using an add_filter?
- an action hook when a post reaches a certain number of views
- WordPress overwrites UNC
- Excluding posts by meta, and also keeping posts without the meta
- Replace Data In Post & Update Meta Field Post Is Saved
- How to optionally append components to the output of a gutenberg block?
- How to add custom media library mime icons?
- Custom SQL query slows down when using multiple OR … LIKE … in posts_where filter
- get_post() with filters applied
- Ajax filter – show all results that contain at least one filter
- WP_Query filter by custom meta
- Drop down filter sort posts by latest, last 7 days and monthly
- How to add a blog filter bar without paying money. (example inside)
- oembed_dataparse filter not running at all for standard YouTube embed
- Filter wp_mail based on content type
- Add filter conditionally to a page
- mu-plugins body_class filter not working
- shortcode function outputs multiple anchor tags
- Show child theme for users on specific IP
- wp.getPosts with status = ‘trash’ using node.js
- Is there a way to overwrite a filter used in canonical.php?
- Adding an orderby filter, casting postmeta with multiple keys
- post->post_content filter
- How to change this WP logo and posts url in block editor?
- How to elect position of new item output in a dropdown when using add_filter
- Query Multiple Filters, one with Meta
- How to remove a filter that is an object method?