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
- Valid characters for actions, hooks and filters
- Single loop for wp_query and wp_user_query
- query multiple taxonomies
- Custom Post Type, WP_Query and ‘orderby’
- Grab 5 latest posts from custom post type ‘announcements’
- Pagination Doesn’t Work
- Numeric pagination custom post type
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Custom post type archive sorted and grouped by date in post meta field
- Actions that Run on Admin Edit Page Load After Posts Are Queried
- Having trouble with custom date field for CPT query (WordPress)
- Quickest way to get last or oldest post date – WP Query
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Use get_post_types to query only custom posts types
- Query custom post type by category slug
- Search / Filter posts on Title/Content OR Tags
- Several post types on WP Query by tag and taxonomy
- Categories filtering in new post
- custom post type search by reference id
- Print current post category during WP_Query
- remove_action not removing add_action from constructor
- Retrieving meta-box from a custom-post-type
- Cannot get custom post
- providing access to post_id or post inside functions.php
- Remove actions/filters that are set with create_function()
- Display custom post type for specific user
- Use has_filter on comment_post
- WP Query from two Custom Post type fields as statement
- Query to Exclude Child Pages from Custom Post Type Archive
- How to output custom post type title on custom page with category next to it?
- How to sort by multiple values in a nested WP_Query
- Add filter button to custom post type in admin area
- SQL LIKE in WP_Query
- Values inside a custom field to determine which category posts to display
- WP_Query get posts where post_name is empty
- How do I sort post listing by child post count?
- Can I add a wordpress page using the slug for a CPT rewrite