How to filter / exclude posts by id in list of posts in WordPress Dashboard / Admin -
so, trying filter list of posts (mine custom post type) in wordpress dashboard id.
i checking area (custom widget) see if user can edit given post (not, intentionally dodging wordpress roles, etc), if cannot want filter/exclude post list.
i want take list:
...and filter out post id's function returns
okay, i've answered own question. here code on how did it.
function exclude_list_per_function( $query ) { global $wpdb; //gets post id's, know bit of hack $querystr = " select $wpdb->posts.id $wpdb->posts "; $post_ids = $wpdb->get_results($querystr, object); //go through each post , pass function returns true if user_can, , false if user_can't foreach($post_ids $post_obj){ if(!can_user_other_function_view_this_post(get_post($post_obj->id))){ //if they_can't, add them array excluded $posts_not_in[]=$post_obj->id; } } //set posts excluded list. $query->set( 'post__not_in', $posts_not_in ); } add_action( 'pre_get_posts', 'exclude_list_per_function');
Comments
Post a Comment