Untested:
function custom_home_exclude( $where="" ) {
$exclude = array();
$newsQuery = new WP_Query (array(
"post_type" => "news",
"meta_key" => "post_to_blog",
"meta_value" => 1,
"meta_compare" => "!=",
"posts_per_page" => "-1",
));
while ($newsQuery->have_posts()) {
$newsQuery->the_post();
array_push($exclude, get_the_ID());
}
wp_reset_query();
$exclude = join(',', $exclude);
$where .= " AND `ID` NOT IN ($exclude)";
return $where;
}
function custom_home_loop($query) {
if ($query->is_main_query() && is_home()) {
$query->set("post_type", array("post", "news"));
add_filter( 'posts_where', 'custom_home_exclude' );
}
}
add_filter("pre_get_posts", "custom_home_loop");
Related Posts:
- Remove “Get Shortlink” button in admin of custom post type
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- How to enqueue scripts on custom post add/edit pages?
- remove custom post type permalink
- How to change “Draft” string for status of custom post type to “Unavailable”?
- Adding a drag and drop re-ordering from a custom post type default list [closed]
- get_query_var() not working in pre_get_posts
- Unregister post type from child theme
- Filter for “get_post_type_archive_link()”
- How to correctly get post type in a the_title filter
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- With what hook can I address all posts from all custom post types when they are published?
- Make the ‘all’ filter default instead of ‘mine’ in a custom post type
- wp_query and comment_parent – select only posts with top level comments
- Want to filter only parent post in admin area
- What hook should be used to programmatically create a post only when master post is updated?
- How to register custom post types in a plugin?
- How to get Custom Post ID by adding filter to child theme’s function
- Custom post_type search’s $wp_query->query_vars do not correspond
- Can’t unregister parent theme’s CPT from my child theme
- Modifying date filter on admin page for custom post type to link to custom field
- Add html to cpt main page / admin edit.php
- register_taxonomy and register_post_type does not work [closed]
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Setting proper query for multiple custom admin filters
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- Genesis filterable portfolio isotope [closed]
- Filtering WP_Query
- Displaying custom taxonomy in the admin list of a custom post type
- creat filter with wp_query
- How can I made custom taxonomies relationship?
- How can I add a filter to a particular post format?
- Is there any way to get list of all possible filter hooks for all post types?
- Can I display custom post types in home.php or need page template?
- Create new custom post and post category of same name
- Use remove_meta_box conditionally on custom post type
- wp_trash_post action hook with custom post type
- How do I amend form data before it is saved for a custom post type
- sortable columns for multiple custom post types not working
- Catch and display error on save_post action
- How to recover the post ID earlier in the WP admin hook action “firing” sequence?
- conditional filter
- Using `set_transient()` when saving a custom post type
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- Best way to fix bad count on All | Mine | Published
- WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)
- Store a value in global scope after init hook is fired
- Dynamic page for nav items used as filters
- Filter posts by their related field’s custom field
- Post Click Redirect to Custom URL instead of Single Post Page
- Sort custom post archives by a meta value from a different custom post type?
- How to use multiple orderby conditions on query search results? (orderby one post type, relevance)
- Output all terms slugs for a loop filter
- How to store additional data that is related to core data
- Keep br tags from stripping
- Adding Information To All Posts Screen
- do action inside a class is not working
- Filter Content on all Post Types
- Filter wp_dropdown_categories Per Post Type
- Hook only specific post type
- Dynamically change post_parent in every page load?
- Create action running on trashed_post hook to modify post_meta value
- Change CPT Edit Target Link for Admin List
- Custom post type template not loading from plugin
- Add a post when another post type is inserting
- Show message when query has no posts
- How to sort a WP_Query by a custom field AND ALSO filter by a different custom field
- WP_Query of custom post type sorted by meta_key has unexpected results
- WordPress hook after post content and meta update
- How to show all taxonomies within custom post type loop
- ACF for custom post type archive pages: which hook to use?
- Undefined $post in wp_query
- Returning a custom content types with meta values
- Adding Multiple Post Types to Query [duplicate]
- WordPress hook which triggers on post import
- Assigning alternate single-{cpt} template based on blog_id in multisite
- providing access to post_id or post inside functions.php
- WP_Query not resetting after wp_reset_postdata
- Remove actions/filters that are set with create_function()
- How to get the post terms from a child taxonomy
- WP_Query – How to get all posts of specific days of week by custom field date?
- Before saving post hook
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- display posts of custom post type with custom taxonomy
- WP_Query order by two values
- Get The Caller (Plugin / Theme / Core) For All actions & Hook in WordPress
- Get current user id
- List categories, subcategories and posts from custom taxonomy and custom post type
- Problem with Apply Filters on URL in meta box filed of custom port type
- How to query for posts (hierarchical custom post type) that have children but are NOT top level?
- Custom post type and custom taxonomy 404 on page 2
- WP Query results showing posts outside of category ID
- tax_query (if the terms are empty)
- Custom post type to lead to single post type instead of shortcode modal
- Remove tags without a specific meta key from “choose from the most used tags”
- Display custom post type for specific user
- how to retain the ability to modify the post slug after applying a post_type_link filter?
- Cannot get custom posts by category
- Custom Post type loop with ACF not displaying properly
- Get all post from a post type