Skip to content

Commit 0e6906d

Browse files
committed
Add separate configuration option for number of results items display within modal and inline variants. SC-1891
1 parent 39c051c commit 0e6906d

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

admin/class-searchcraft-admin.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,20 @@ private function searchcraft_on_layout_settings_config_request( $request ) {
14981498
update_option( 'searchcraft_view_all_results_label', $view_all_results_label );
14991499
}
15001500

1501+
// Handle overlay results per page setting.
1502+
if ( isset( $request['searchcraft_overlay_results_per_page'] ) ) {
1503+
$overlay_results_per_page = absint( wp_unslash( $request['searchcraft_overlay_results_per_page'] ) );
1504+
1505+
// Validate the overlay results per page value (between 1 and 20).
1506+
if ( $overlay_results_per_page < 1 ) {
1507+
$overlay_results_per_page = 1;
1508+
} elseif ( $overlay_results_per_page > 20 ) {
1509+
$overlay_results_per_page = 20;
1510+
}
1511+
1512+
update_option( 'searchcraft_overlay_results_per_page', $overlay_results_per_page );
1513+
}
1514+
15011515
// Handle retain get_search_form setting.
15021516
$retain_get_search_form = isset( $request['searchcraft_retain_get_search_form'] ) ? true : false;
15031517
update_option( 'searchcraft_retain_get_search_form', $retain_get_search_form );

admin/partials/searchcraft-admin-layout-tab.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
$search_experience = get_option( 'searchcraft_search_experience', 'full' );
3636
$include_filter_panel = get_option( 'searchcraft_include_filter_panel', false );
3737
$results_per_page = get_option( 'searchcraft_results_per_page', 10 );
38+
$overlay_results_per_page = get_option( 'searchcraft_overlay_results_per_page', 5 );
3839
$enable_most_recent_toggle = get_option( 'searchcraft_enable_most_recent_toggle', '1' );
3940
$enable_exact_match_toggle = get_option( 'searchcraft_enable_exact_match_toggle', '1' );
4041
$enable_date_range = get_option( 'searchcraft_enable_date_range', '1' );
@@ -276,6 +277,21 @@
276277
</p>
277278
</td>
278279
</tr>
280+
<tr class="searchcraft-popover-only">
281+
<th scope="row">
282+
<label for="searchcraft_overlay_results_per_page">Results in Overlay</label>
283+
</th>
284+
<td>
285+
<select name="searchcraft_overlay_results_per_page" id="searchcraft_overlay_results_per_page" class="regular-text">
286+
<?php for ( $i = 1; $i <= 20; $i++ ) : ?>
287+
<option value="<?php echo esc_attr( $i ); ?>" <?php selected( $overlay_results_per_page, $i ); ?>><?php echo esc_html( $i ); ?></option>
288+
<?php endfor; ?>
289+
</select>
290+
<p class="description">
291+
Number of search results to display in the modal or inline overlay. Default is 5 results.
292+
</p>
293+
</td>
294+
</tr>
279295
</tbody>
280296
</table>
281297
</div>

public/class-searchcraft-public.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ public function get_js_config() {
302302
$oldest_post_year = $admin_instance->get_oldest_post_year();
303303
$js_config['oldestPostYear'] = $oldest_post_year;
304304

305-
$js_config['resultsPerPage'] = intval( get_option( 'searchcraft_results_per_page', 10 ) );
305+
$js_config['resultsPerPage'] = intval( get_option( 'searchcraft_results_per_page', 10 ) );
306+
$js_config['overlayResultsPerPage'] = intval( get_option( 'searchcraft_overlay_results_per_page', 5 ) );
306307

307308
// Filter taxonomies.
308309
$filter_taxonomies = get_option( 'searchcraft_filter_taxonomies', array() );

public/js/searchcraft-sdk-integration.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,21 @@
6767
return;
6868
}
6969
const isWPSearchPage = searchcraft_config.isWPSearchPage || false;
70+
71+
// Determine which results per page setting to use
72+
// Use overlayResultsPerPage for modal/inline when NOT on search page
73+
// Use regular resultsPerPage for full experience or when on search page
74+
let resultsPerPage = parseInt(searchcraft_config.resultsPerPage) || 10;
75+
if (!isWPSearchPage && searchcraft_config.overlayResultsPerPage) {
76+
resultsPerPage = parseInt(searchcraft_config.overlayResultsPerPage) || 5;
77+
}
78+
7079
const config = {
7180
indexName: searchcraft_config.indexName,
7281
readKey: searchcraft_config.readKey,
7382
endpointURL: searchcraft_config.endpointURL,
7483
searchDebounceDelay: 50,
75-
searchResultsPerPage: parseInt(searchcraft_config.resultsPerPage) || 10
84+
searchResultsPerPage: resultsPerPage
7685
};
7786

7887
// Add cortexURL if AI summary is enabled

0 commit comments

Comments
 (0)