Skip to content

Commit

Permalink
Merge pull request #11 from imtiazUAP/redirect
Browse files Browse the repository at this point in the history
introduced on search redirect for homepage
  • Loading branch information
ImtiazScript authored Jul 31, 2023
2 parents 6d85d75 + a826b57 commit c681a33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion public/travel-packages-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ function travel_packages_shortcode($atts)
$atts = shortcode_atts(
array(
'limit' => -1,
'redirect' => '',
),
$atts
);

$on_search_redirect = isset($atts['redirect']) ? $atts['redirect'] : '';
// Pass the PHP value inline to the JavaScript file
$inline_script = 'var travelPackagesFilter = { redirectValue: "' . esc_js($on_search_redirect) . '" };';
wp_add_inline_script('travel-packages-shortcode-script', $inline_script);

// Getting the country names for the country filter drop-down
$allPackages = new WP_Query([
'post_type' => 'travel-package',
Expand Down Expand Up @@ -174,7 +180,7 @@ function travel_packages_shortcode($atts)
)
);

if ($pagination_links) {
if ($pagination_links && !$on_search_redirect) {
echo '<div class="pagination-wrapper">';
echo '<div class="pagination">';
echo $pagination_links;
Expand Down
7 changes: 6 additions & 1 deletion scripts/javascripts/travel-packages-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ document.getElementById('package-filter-form').addEventListener('submit', functi
url.searchParams.delete('tp_page'); // Remove tp_page from the URL
}

window.location.href = url.href; // Redirect to filtered URL
// Check if the 'redirectValue' is not empty
if (travelPackagesFilter.redirectValue && travelPackagesFilter.redirectValue !== "") {
window.location.href = travelPackagesFilter.redirectValue + "?" + url.searchParams.toString();
} else {
window.location.href = url.href;
}
});

2 changes: 1 addition & 1 deletion travel-packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Travel Packages
Plugin URI: https://imtiaz.cloud
Description: Display travel packages on your website.
Version: 1.4
Version: 1.6
Author: Imtiaz Ahmed
Author URI: https://imtiaz.cloud
License: GPL2
Expand Down

0 comments on commit c681a33

Please sign in to comment.