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
- 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
- AAPF Filter group is not in widget section
- Customize register form page with add_action or apply_filter
- filter on the_content stopped working when I updated to WP 3.6.1
- Replace Paid Shipping Method With Free Shipping Method WooCommerce [duplicate]
- How to use in_category?
- get_the_excerpt on mobile still displays continue reading
- How to reset/remove added filters ‘posts_join’ and ‘posts_orderby’ after the loop is completed?
- Wrapping Featured Image on Add/Edit Page in div?
- remove_filter excerpt_more from a plugin class
- Date filter for post query not filtering results when variable outside the function
- How do I remove certain HTML elements with specific classes from the feed?
- Passing variable from filter
- How to turn this customized core function into a filter/action in functions.php?
- dynamically filter by category via sub-menu
- Turn wp_tag_cloud into a front-end filter
- Custom excerpt_more filter not working when tag is present
- Adding an orderby filter, casting postmeta with multiple keys
- How we make the filter for fornt end user
- Filter image and text from post format
- Identify admin/logout and more filters
- Add Default WordPress Formatting To Data From External SQL Tables?
- Sanitizing a custom query’s clauses
- How can I display wp_link_pages before a shortcode, if it is used, or display after content?
- Clean/filter HTML inserted to post content by XML RPC
- Filter and Search
- How to separate a specific page’s comments from other comments
- What is the scope and persistence of add_filter() and remove_filter()?
- how to localize the number of wordpress post views?
- Which hook should be used in this case?
- confusion with add_filter
- add_filter with specific thumb names
- post->post_content filter
- Override typo in multiple parent theme files?
- Add HTML to Page Content
- Categorize posts on a page o the basis of category of other post on the same page
- How properly write function to filter content in a template for plugin “multiple content blocks”
- Filter dashboard custom post listing by user
- Taxonomy search filters
- Joining tables not working in the post editor page
- How to create a list of terms who’s posts also have a predefined external term?
- Is it possible to make get variable out of filter in Class?
- Getting entry ID from frm_email_message filter in formidable
- Replace image scr with it’s surrounding href
- GET form action. Redirect to self
- Filter posts by multiple checkbox categories
- manage_users_custom_columns filter not firing callback functions
- ACF Load Field Groups Programmatically [closed]
- Conditionally including JS based on whether ACF field is set [closed]
- WooCommerce comments_template Filter Not Firing
- Auto append text after the title?
- Remove pipe in views admin page filter
- Woocommerce: Only one review per verified buyer [closed]
- After adding filter to plugin’s code, post’s content doesn’t display
- if i put the code in my theme’s function.php file can it work?
- Admin New Order: Autofocus on Search a product
- Is there a hook or filter that adds a button to the left of the search box?
- Why does using excerpt_more filter change link location?
- NextGEN Gallery: Adding drop-down menu widget to gallery view without modifying plugin code [closed]
- How to filter part of a variable if it is no array?
- filter a list by gender
- str_replace css meta tag?
- How do you disable the verification process of user email changes?
- How to add custom HTML attribute to reusable block div in WordPress admin
- Modify the third (context) parameter in a filter?
- How to change this WP logo and posts url in block editor?
- Filter and manipulate the get_current_user() function
- Footnotes with dynamic title attributes?
- add_filter(‘the_content’, ‘method’) does not trigger my custom method
- Can you call a filter hook by “add_action”?
- WordPress wp_lazy_loading_enabled returns loading attribute set to lazy