/**
* Filter all the posts in POST -> Edit for doesn't display
* the posts created using some write panel.
*/
public static function ExcludeWritepanelsPosts($where)
{
global $wpdb, $parent_file;
$types = array('edit.php', 'edit-pages.php', 'edit.php?post_type=page');
if (!in_array($parent_file, $types)) {
return $where;
}
require_once 'RCCWP_Options.php';
$exclude = RCCWP_Options::Get('hide-non-standart-content');
if ($exclude == false) {
return $where;
}
if (empty($_GET['filter-posts'])) {
$where = $where . " AND 0 = (SELECT count({$wpdb->postmeta}.meta_value) FROM {$wpdb->postmeta} WHERE {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID and {$wpdb->postmeta}.meta_key = '_mf_write_panel_id')";
}
//is search
if (isset($_GET['s']) && isset($_GET['filter-posts'])) {
$remove = "/and wp_postmeta.meta_key = '_mf_write_panel_id' and wp_postmeta.meta_value = '(\\w)'/";
$where = preg_replace($remove, "", $where);
$sql = $wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = '%s'", array("_mf_write_panel_id", $_GET['custom-write-panel-id']));
$results = $wpdb->get_results($sql);
if (count($results) == 0) {
return $where;
}
$postIDs = array();
foreach ($results as $result) {
$postIDs[] = $result->post_id;
}
if (count($postIDs) == 1) {
$postIDs[] = $postIDs[0];
}
$where .= sprintf(" AND {$wpdb->posts}.ID IN (%s)", implode(",", $postIDs));
}
return $where;
}