Skip to content

Commit

Permalink
Add a way to find empty data in content overview filters #1578
Browse files Browse the repository at this point in the history
  • Loading branch information
olatechpro committed Apr 25, 2024
1 parent abcd4b0 commit 5e580bd
Showing 1 changed file with 52 additions and 16 deletions.
68 changes: 52 additions & 16 deletions modules/content-overview/content-overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,8 @@ public function filter_get_param_text($param)
// Sure, this could be done in one line. But we're cooler than that: let's make it more readable!
if (! isset($_GET[$param])) {
return null;
} elseif ($_GET[$param] == '0') {
return 0;
} elseif (empty($_GET[$param])) {
return '';
}
Expand Down Expand Up @@ -2018,15 +2020,15 @@ public function content_overview_filters()

private function meta_query_operator($operator = false) {
$operators = [
'equals' => '=',
'not_equals' => '!=',
'greater_than' => '>',
'greater_than_or_equals' => '>=',
'less_than' => '<',
'less_than_or_equals' => '<=',
'like' => 'LIKE',
'not_like' => 'NOT LIKE',
'not_exists' => 'NOT EXISTS'
'equals' => '=',
'not_equals' => '!=',
'greater_than' => '>',
'greater_than_or_equals' => '>=',
'less_than' => '<',
'less_than_or_equals' => '<=',
'like' => 'LIKE',
'not_like' => 'NOT LIKE',
'not_exists' => 'NOT EXISTS/EMPTY',
];

if ($operator) {
Expand Down Expand Up @@ -2401,7 +2403,11 @@ class="date-time-pick"
<?php
$all_options = $this->meta_query_operator();
foreach ($all_options as $option_key => $option_label) {
if ($operator_value == $option_key && !empty($selected_value)) {
if (
($operator_value == $option_key && !empty($selected_value))
|| ($operator_value == $option_key && $selected_value == '0')
|| ($operator_value == $option_key && 'not_exists' === $option_key)
) {
$selected_value = $option_label . $selected_value;
}
echo '<option value="' . esc_attr($option_key) . '" ' . selected(
Expand Down Expand Up @@ -2650,19 +2656,49 @@ public function getPostsForPostType($postType, $args = null)
);
}

} elseif(in_array($enabled_filter, $this->content_overview_datas['meta_keys']) && !empty($this->user_filters[$enabled_filter])) {
} elseif(
in_array($enabled_filter, $this->content_overview_datas['meta_keys'])
&& (
isset($this->user_filters[$enabled_filter])
&&
(
!empty($this->user_filters[$enabled_filter])
|| $this->user_filters[$enabled_filter] == '0'
|| (
!empty($this->user_filters[$enabled_filter . '_operator'])
&& $this->user_filters[$enabled_filter . '_operator'] === 'not_exists'
)
)
)
) {
// metakey filter
unset($args[$enabled_filter]);
$meta_value = sanitize_text_field($this->user_filters[$enabled_filter]);
$meta_operator = !empty($this->user_filters[$enabled_filter . '_operator']) ? $this->user_filters[$enabled_filter . '_operator'] : 'equals';
$compare = $this->meta_query_operator($meta_operator);

$metadata_filter = true;
$meta_query[] = array(
'key' => $enabled_filter,
'value' => $meta_value,
'compare' => $compare
);

if ($meta_operator == 'not_exists') {
$meta_query[] = array(
'relation' => 'OR',
array(
'key' => $enabled_filter,
'compare' => 'NOT EXISTS'
),
array(
'key' => $enabled_filter,
'value' => '',
'compare' => '='
)
);
} else {
$meta_query[] = array(
'key' => $enabled_filter,
'value' => $meta_value,
'compare' => $compare
);
}
} elseif (in_array($enabled_filter, ['ppch_co_yoast_seo__yoast_wpseo_linkdex', 'ppch_co_yoast_seo__yoast_wpseo_content_score']) && !empty($this->user_filters[$enabled_filter]) && array_key_exists($enabled_filter, $this->form_filter_list) && class_exists('WPSEO_Meta')) {
// yoast seo filter
unset($args[$enabled_filter]);
Expand Down

0 comments on commit 5e580bd

Please sign in to comment.