I’m not entirely sure what the problem is, because you’ve already mentioned all the tools that you need to solve it…
Just use pre_get_posts
filter, check if the user is logged in, get the IDs of posts he should not see and exclude them in query:
function remove_some_posts_for_user( $query ) {
if ( ! is_admin() && is_user_logged_in() && $query->is_main_query() ) {
$posts_to_remove_for_current_user = get_user_meta( get_current_user_id(), 'posts_to_remove', true );
if ( ! empty($posts_to_remove_for_current_user) is_array($posts_to_remove_for_current_user) ) {
$query->set( 'post__not_in', $posts_to_remove_for_current_user );
}
}
}
add_action( 'pre_get_posts', 'remove_some_posts_for_user' );
Related Posts:
- Is there any difference between hooks posts_where with posts_join and posts_search performance wise?
- Select User by Joining Multiple Meta Value Results
- Plugin will sort users by usermeta
- Problem when try to add ++1 for user meta
- Query Nickname rather than Display Name in custom Woocommerce plugin
- Combining two meta_values within one row with query
- How to do a sql like query on serialized data of user meta data
- Querying users by meta value and getting a strange answer
- Update vs Insert logic but the last key is always inserted?
- list or get meta_key where meta_value is ‘something’
- Custom query_var causes displaying posts archive on front page
- What is the most efficient way of implementing a favorite post system?
- Why does get_the_time(‘F j’) return November 30 for all posts?
- Query by one meta_key and sort by another (possibly NULL value)
- Very slow query
- Search Terms – Querying on either description__like OR name__like in the same Term Query?
- Query & Sort Comments by custom comment meta
- is_archive() doesn’t work on public query var archive pages?
- How to get category link without a database query
- How to count get_users query?
- cron job to auto delete posts of a specific post type older than x days
- Possible to get posts from multiple meta keys/values in a single query?
- Difference between fragment caching and wp_cache
- mysql query paging
- How to display all posts with today’s same month and day only?
- Show featured image as background image from postQuery
- Using $wpdb->update but confused on the WHERE in and SET
- You have an error in your SQL syntax – Help with query
- Make one query for adding entries to database
- WordPress Loop: List All Posts by a Category & Subcategory
- Order query by post meta value
- add_query_arg() and empty variables inside
- Query Strings and Woocommerce
- Style Post Differently In Query
- WordPress post type “event” query string fix?
- how would I create a custom query to get all users, and a related post based on a postmeta field?
- Display posts with a start OR end date later than current date
- mysql query two database tables, users and usermeta and sort by custom meta int value
- order one custom post type by modified time of another post type
- is_search called incorreclty
- Function to delete a post, it’s children and it’s grand children (half way there already)
- Query to Get All Users from wp_users With NO matching user_id In wp_usermeta
- Nested loop : wich way/order?
- Dynamically adjust single-posttype.php query, based on current taxonomies
- Passing parameters to a static front page
- wp_list_pages() refuses to output posts
- Can’t seem to do combined query AND sort?
- Use mysql_query instead of $wpdb query
- Post with certain term and without any term
- Custom Query – Based on user input
- Change the destination of the URLs in post.php
- Page with custom template make get request to a custom route – Pseudo code
- get_users with array as meta_value
- How to delete all posts, categories and tags from WordPress database
- Ideas how to search & replace post_content when string contains a newline?
- How to insert Collate into WordPress search query?
- Query the WordPress database to get data together with replaced information
- $wpdb->prepare affecting the query?
- WordPress SQL search, how to handle SQL Injection?
- Optimize slow SQL query for multiple meta values
- Query for Custom Post Type UI Does Not Loop All the Post
- Updating with $qpdb->query() always returns 0 rows affected
- How to manage a particular “order by” for get_search_query()?
- Query to view scheduled or draft post
- How to return count of custom post type posts with a specific custom field value via $wpdb?
- How can I get the name of term post meta value which equals term id
- Help with Related Posts Function
- Trying to use WP_Query to return post with and without meta values
- How to add a Variable to post query
- Sort a list of a CPT ( job) if a meta is empty
- SQL query to delete users with multiple meta keys and comments
- Restore WordPress Backup Locally?
- Trouble migrating custom post types from non-wordpress cms
- “order” does not affect order of custom query
- Create a new post on a specified publish date via link?
- Exclude Posts from a Widget
- New custom post type entries are not sorted correctly in admin using pre_get_posts
- Query String for the WP_QUERY parameters
- Counting And Monitoring How Much Queries My Script Used
- $wpdb query for price in custom field value
- Run an update query in a function
- Add generic page to WP_Query
- Advanced Custom Fields Query with Different Values of the Same Key
- Multiple terms not working on taxonomy
- Sorting of coupons in the right way
- search.php is not generating the right results
- excludeCat function reverses order of blog posts
- Slow query when joining wp_posts with a lookup-table?
- Run search query again without pagination gives no results?
- Mysql query and odd results
- Using wp_list_table how to trigger update function “inline”?
- Filter multiple different main queries on custom pages
- WP_Query orderby meta key/value suddely stopped working
- WP_Query older new links navigation?
- Where can I find the SQL to get the most used information by wordpress database?
- WooCommerce Total # orders [closed]
- How do I troubleshoot Maximum execution time of 60 seconds exceeded in updating a Media File?
- update $wpdb one query
- Admin Post List table Query filtering “WHERE” for custom post type
- How to use a dynamic term id for the query block