Skip to content

Commit

Permalink
Merge pull request #1655 from publishpress/feature/#1654_Content_Over…
Browse files Browse the repository at this point in the history
…view_and_Content_board_using_english_label_in_meta_query_filter

feature/#1654_Content_Overview_and_Content_board_using_english_label_in_meta_query_filter
  • Loading branch information
olatechpro authored May 22, 2024
2 parents ecfba36 + 34f0003 commit bd4b411
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
30 changes: 26 additions & 4 deletions modules/content-board/content-board.php
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,7 @@ public function content_board_filters()
return apply_filters('PP_Content_Board_filter_names', $select_filter_names);
}

private function meta_query_operator($operator = false) {
private function meta_query_operator_label($operator = false) {
$operators = [
'equals' => 'Equals (=)',
'not_equals' => 'Does not equal (!=)',
Expand All @@ -2114,6 +2114,28 @@ private function meta_query_operator($operator = false) {
return $return;
}

private function meta_query_operator_symbol($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',
];

if ($operator) {
$return = array_key_exists($operator, $operators) ? $operators[$operator] : $operator;
} else {
$return = $operators;
}

return $return;
}

public function content_board_filter_options($select_id, $select_name, $filters)
{

Expand Down Expand Up @@ -2475,7 +2497,7 @@ class="date-time-pick"
<div class="filter-content">
<select class="non-trigger-select" id="filter_<?php echo esc_attr($select_name); ?>_operator" name="<?php echo esc_attr($select_name); ?>_operator">
<?php
$all_options = $this->meta_query_operator();
$all_options = $this->meta_query_operator_label();
foreach ($all_options as $option_key => $option_label) {
if (
($operator_value == $option_key && !empty($selected_value))
Expand Down Expand Up @@ -2923,7 +2945,7 @@ public function getPostsForPostType($postType, $args = null)
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);
$compare = $this->meta_query_operator_symbol($meta_operator);

$metadata_filter = true;

Expand Down Expand Up @@ -2953,7 +2975,7 @@ public function getPostsForPostType($postType, $args = null)
$meta_value = sanitize_text_field($this->user_filters[$enabled_filter]);
$meta_key = str_replace('ppch_co_yoast_seo_', '', $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);
$compare = $this->meta_query_operator_symbol($meta_operator);
$metadata_filter = true;
$meta_query[] = array(
'key' => $meta_key,
Expand Down
30 changes: 26 additions & 4 deletions modules/content-overview/content-overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,7 @@ public function content_overview_filters()
return apply_filters('PP_Content_Overview_filter_names', $select_filter_names);
}

private function meta_query_operator($operator = false) {
private function meta_query_operator_label($operator = false) {
$operators = [
'equals' => 'Equals (=)',
'not_equals' => 'Does not equal (!=)',
Expand All @@ -2047,6 +2047,28 @@ private function meta_query_operator($operator = false) {
return $return;
}

private function meta_query_operator_symbol($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',
];

if ($operator) {
$return = array_key_exists($operator, $operators) ? $operators[$operator] : $operator;
} else {
$return = $operators;
}

return $return;
}

public function content_overview_filter_options($select_id, $select_name, $filters)
{

Expand Down Expand Up @@ -2408,7 +2430,7 @@ class="date-time-pick"
<div class="filter-content">
<select class="non-trigger-select" id="filter_<?php echo esc_attr($select_name); ?>_operator" name="<?php echo esc_attr($select_name); ?>_operator">
<?php
$all_options = $this->meta_query_operator();
$all_options = $this->meta_query_operator_label();
foreach ($all_options as $option_key => $option_label) {
if (
($operator_value == $option_key && !empty($selected_value))
Expand Down Expand Up @@ -2682,7 +2704,7 @@ public function getPostsForPostType($postType, $args = null)
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);
$compare = $this->meta_query_operator_symbol($meta_operator);

$metadata_filter = true;

Expand Down Expand Up @@ -2712,7 +2734,7 @@ public function getPostsForPostType($postType, $args = null)
$meta_value = sanitize_text_field($this->user_filters[$enabled_filter]);
$meta_key = str_replace('ppch_co_yoast_seo_', '', $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);
$compare = $this->meta_query_operator_symbol($meta_operator);
$metadata_filter = true;
$meta_query[] = array(
'key' => $meta_key,
Expand Down

0 comments on commit bd4b411

Please sign in to comment.