Skip to content

Commit

Permalink
Merge pull request #3007 from 10up/feature/2610
Browse files Browse the repository at this point in the history
Add option to toggle term counter
  • Loading branch information
felipeelia authored Oct 11, 2022
2 parents ab6f068 + 2741cfa commit d14cca0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion assets/js/instant-results/components/common/checkbox-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { __, _n, sprintf } from '@wordpress/i18n';
*/
import Checkbox from './checkbox';
import SmallButton from './small-button';
import { termCount } from '../../config';

/**
* Checkbox list component.
Expand Down Expand Up @@ -124,6 +125,10 @@ export default ({ disabled, label, options, onChange, selected, sortBy }) => {
*/
const displayOption = ({ count, id, label, value }) => {
const children = childOptions[value];
/**
* Check for term count option.
*/
const counter = termCount === '1' ? count : '';

if (!showAll && optionsShown >= optionsLimit) {
return <Fragment key={value} />;
Expand All @@ -133,7 +138,7 @@ export default ({ disabled, label, options, onChange, selected, sortBy }) => {
<li className="ep-search-options-list__item" key={value}>
<Checkbox
checked={selected.includes(value)}
count={count}
count={counter}
disabled={disabled}
id={id}
label={label}
Expand Down
2 changes: 2 additions & 0 deletions assets/js/instant-results/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
paramPrefix,
postTypeLabels,
taxonomyLabels,
termCount,
} = window.epInstantResults;

/**
Expand Down Expand Up @@ -72,4 +73,5 @@ export {
postTypeLabels,
sortOptions,
taxonomyLabels,
termCount,
};
15 changes: 15 additions & 0 deletions includes/classes/Feature/InstantResults/InstantResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function __construct() {
'highlight_tag' => 'mark',
'facets' => 'post_type,category,post_tag',
'match_type' => 'all',
'term_count' => '1',
];

$settings = $this->get_settings() ? $this->get_settings() : array();
Expand Down Expand Up @@ -171,6 +172,18 @@ public function output_feature_box_settings() {
<p class="field-description"><?php esc_html_e( '"All" will only show content that matches all facets. "Any" will show content that matches any facet.', 'elasticpress' ); ?></p>
</div>
</div>
<div class="field">
<div class="field-name status"><?php esc_html_e( 'Term Count', 'elasticpress' ); ?></div>
<div class="input-wrap">
<label>
<input name="settings[term_count]" <?php checked( (bool) $this->settings['term_count'] ); ?> type="radio" value="1"><?php esc_html_e( 'Enabled', 'elasticpress' ); ?>
</label><br>
<label>
<input name="settings[term_count]" <?php checked( ! (bool) $this->settings['term_count'] ); ?> type="radio" value="0"><?php esc_html_e( 'Disabled', 'elasticpress' ); ?>
</label>
<p class="field-description"><?php esc_html_e( 'When enabled, it will show the term count in the instant results widget.', 'elasticpress' ); ?></p>
</div>
</div>

<?php
}
Expand Down Expand Up @@ -281,6 +294,7 @@ public function enqueue_frontend_assets() {
'matchType' => $this->settings['match_type'],
'paramPrefix' => 'ep-',
'postTypeLabels' => $this->get_post_type_labels(),
'termCount' => $this->settings['term_count'],
)
);
}
Expand Down Expand Up @@ -923,4 +937,5 @@ public function get_args_schema() {
}
return $args;
}

}

0 comments on commit d14cca0

Please sign in to comment.