Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/#1654_Content_Overview_and_Content_board_using_english_label_in_meta_query_filter #1655

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading