Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Randy A

    (@randy-a)

    I was able to build a workaround that does not require modifying the plugin in any way.

    To those wondering what I’ve done, I created a ‘post_where’ filter that applies a custom where clause to the meta query like this (assuming there is a custom field of type User with keyname set to ‘prohibited_users’):

    function restrictToUser($where){
    	global $wpdb;
    	$user_id = get_current_user_id();
    	$where .= " AND '$user_id' NOT IN (SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = wp_posts.ID AND meta_key='prohibited_users')";
    	return $where;
    }
    add_filter('posts_where', 'restrictToUser');

    and then I ensure that the query args passed to WP_Query had 'suppress_filters' => false set.

    Thread Starter Randy A

    (@randy-a)

    I understand what you mean, but unfortunately my experiments with Meta Queries have shown that since users are stored with the same key name, only the first record is considered in the meta query.

    It would make more sense (for my use case) for multiple users to be stored in a serialized array, so as to make it compatible with Meta Queries of type “IN” or “NOT IN”.

Viewing 2 replies - 1 through 2 (of 2 total)