Skip to content

Commit 5673106

Browse files
authored
Feature/date query support (#223)
* Adding date query support for after/before * Adding support for date query and date after/before query * Adding date query support for ajax requests. * Release prep * Release prep
1 parent 867a452 commit 5673106

14 files changed

+297
-103
lines changed

README.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: infinite scroll, load more, lazy load, endless scroll, ajax load more
55
Requires at least: 5.0
66
Requires PHP: 5.6
77
Tested up to: 6.7
8-
Stable tag: 7.2.0.1
8+
Stable tag: 7.3.0
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1111

@@ -24,7 +24,7 @@ Ajax Load More is compatible for endless scrolling with popular eCommerce plugin
2424
### Features
2525

2626
- **Shortcode Builder** - Create a custom Ajax Load More shortcode in seconds by adjusting various WordPress query parameters in the inuitive shortcode builder.
27-
- **Query Parameters** - Query WordPress by many different content types. Query by Post Type, Post Format, Date, Category, Tags, Custom Taxonomies, Search Term, Authors and more!
27+
- **Query Parameters** - Query WordPress by many different content types. Query by Post Type, Category, Tags, Custom Taxonomies, Search Term, Date Query, Authors and more!
2828
- **Repeater Templates** - Edit and extend the functionality of Ajax Load More by creating your own repeater template to match the look and feel of your website.
2929
- **Multiple Instances** - Include multiple instances of Ajax Load More on a single page, post or template.
3030
- **Ajax Filtering** - The Ajax Load More [custom filtering](https://connekthq.com/plugins/ajax-load-more/examples/filtering/) method will allow you to filter and update your Ajax query results.
@@ -269,6 +269,10 @@ How to install Ajax Load More.
269269

270270
== Changelog ==
271271

272+
= 7.3.0 - February 6, 2025 =
273+
* NEW: Added Date Query support with `date_query`, `date_query_before` and `date_query_after` parameters.
274+
* UPDATE: Various admin UI/UX updates and code cleanup throughout plugin.
275+
272276
= 7.2.0.1 - January 22, 2025 =
273277
* HOTFIX: Fixed potential issue with the parsing of `meta_query` and `tax_query` parameters when using Preloaded add-on.
274278

admin/functions/licensing.php

-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ function alm_license_activation() {
2525
wp_die( esc_attr__( 'Error - unable to verify nonce, please try again.', 'ajax-load-more' ) );
2626
}
2727

28-
$nonce = $form_data['nonce'];
2928
$type = $form_data['type']; // activate OR deactivate.
3029
$item_id = $form_data['item'];
3130
$license = $form_data['license'];
32-
$url = $form_data['url'];
3331
$upgrade = $form_data['upgrade'];
3432
$status = $form_data['status'];
3533
$key = $form_data['key'];

ajax-load-more.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
* Author: Darren Cooney
88
* Twitter: @KaptonKaos
99
* Author URI: https://connekthq.com
10-
* Version: 7.2.0.1
10+
* Version: 7.3.0
1111
* License: GPL
1212
* Copyright: Darren Cooney & Connekt Media
1313
*
1414
* @package AjaxLoadMore
1515
*/
1616

17-
define( 'ALM_VERSION', '7.2.0.1' );
18-
define( 'ALM_RELEASE', 'January 22, 2025' );
17+
define( 'ALM_VERSION', '7.3.0' );
18+
define( 'ALM_RELEASE', 'February 6, 2025' );
1919
define( 'ALM_STORE_URL', 'https://connekthq.com' );
2020

2121
// Plugin installation helpers.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array(), 'version' => '068a713dbf18febb7e86');
1+
<?php return array('dependencies' => array(), 'version' => 'c7ee979ef153ffed67c6');

build/frontend/ajax-load-more.js

+39-21
Original file line numberDiff line numberDiff line change
@@ -11217,6 +11217,24 @@ function getAjaxParams(alm, queryType) {
1121711217
if (alm.listing.dataset.metaType) {
1121811218
data.meta_type = alm.listing.dataset.metaType;
1121911219
}
11220+
if (alm.listing.dataset.dateQuery) {
11221+
data.date_query = alm.listing.dataset.dateQuery;
11222+
}
11223+
if (alm.listing.dataset.dateQueryAfter) {
11224+
data.date_query_after = alm.listing.dataset.dateQueryAfter;
11225+
}
11226+
if (alm.listing.dataset.dateQueryBefore) {
11227+
data.date_query_before = alm.listing.dataset.dateQueryBefore;
11228+
}
11229+
if (alm.listing.dataset.dateQueryCompare) {
11230+
data.date_query_compare = alm.listing.dataset.dateQueryCompare;
11231+
}
11232+
if (alm.listing.dataset.dateQueryInclusive) {
11233+
data.date_query_inclusive = alm.listing.dataset.dateQueryInclusive;
11234+
}
11235+
if (alm.listing.dataset.dateQueryRelation) {
11236+
data.date_query_relation = alm.listing.dataset.dateQueryRelation;
11237+
}
1122011238
if (alm.listing.dataset.author) {
1122111239
data.author = alm.listing.dataset.author;
1122211240
}
@@ -11374,6 +11392,12 @@ function getRestAPIParams(alm) {
1137411392
meta_compare: alm.listing.dataset.metaCompare,
1137511393
meta_relation: alm.listing.dataset.metaRelation,
1137611394
meta_type: alm.listing.dataset.metaType,
11395+
date_query: alm.listing.dataset.dateQuery,
11396+
date_query_after: alm.listing.dataset.dateQueryAfter,
11397+
date_query_before: alm.listing.dataset.dateQueryBefore,
11398+
date_query_compare: alm.listing.dataset.dateQueryCompare,
11399+
date_query_inclusive: alm.listing.dataset.dateQueryInclusive,
11400+
date_query_relation: alm.listing.dataset.dateQueryRelation,
1137711401
author: alm.listing.dataset.author,
1137811402
year: alm.listing.dataset.year,
1137911403
month: alm.listing.dataset.month,
@@ -12717,61 +12741,52 @@ var isBlockEditor = document.body.classList.contains('wp-admin');
1271712741
*/
1271812742
alm.AjaxLoadMore.adminajax = /*#__PURE__*/function () {
1271912743
var _ref2 = ajax_load_more_asyncToGenerator( /*#__PURE__*/ajax_load_more_regeneratorRuntime().mark(function _callee2(params, type) {
12720-
var _alm_localize4, ajaxurl, _params, _params$cache_slug, cache_slug, data;
12744+
var _alm_localize4, url, _params, _params$cache_slug, cache_slug, data;
1272112745
return ajax_load_more_regeneratorRuntime().wrap(function _callee2$(_context2) {
1272212746
while (1) switch (_context2.prev = _context2.next) {
1272312747
case 0:
12724-
_alm_localize4 = alm_localize, ajaxurl = _alm_localize4.ajaxurl; // Get Ajax URL
12748+
_alm_localize4 = alm_localize, url = _alm_localize4.ajaxurl; // Get Ajax URL
1272512749
_params = params, _params$cache_slug = _params.cache_slug, cache_slug = _params$cache_slug === void 0 ? '' : _params$cache_slug; // Deconstruct query params.
1272612750
/**
1272712751
* Single Posts.
1272812752
* If `single_post_target`, adjust the Ajax URL to the post URL.
1272912753
*/
1273012754
if (alm.addons.single_post && alm.addons.single_post_target) {
12731-
ajaxurl = "".concat(alm.addons.single_post_permalink, "?id=").concat(alm.addons.single_post_id, "&alm_page=").concat(parseInt(alm.page) + 1);
12755+
url = "".concat(alm.addons.single_post_permalink, "?id=").concat(alm.addons.single_post_id, "&alm_page=").concat(parseInt(alm.page) + 1);
1273212756
params = '';
1273312757
}
1273412758

1273512759
// Query Loop || WooCommerce || Elementor.
1273612760
if (alm.addons.queryloop || alm.addons.woocommerce || alm.addons.elementor && alm.addons.elementor_type === 'posts') {
12737-
ajaxurl = getButtonURL(alm, alm.rel);
12761+
url = getButtonURL(alm, alm.rel);
1273812762
params = '';
1273912763
}
1274012764

12741-
// Send HTTP request via axios.
12765+
// HTTP request via axios.
1274212766
_context2.next = 6;
12743-
return lib_axios.get(ajaxurl, {
12767+
return lib_axios.get(url, {
1274412768
params: params
1274512769
}).then(function (response) {
1274612770
if (alm.addons.single_post && alm.addons.single_post_target) {
12747-
// Single Posts
12748-
return singlepostsHTML(alm, response, cache_slug);
12771+
return singlepostsHTML(alm, response, cache_slug); // Single Posts
1274912772
} else if (alm.addons.woocommerce) {
12750-
// WooCommerce.
12751-
return wooGetContent(alm, ajaxurl, response, cache_slug);
12773+
return wooGetContent(alm, url, response, cache_slug); // WooCommerce.
1275212774
} else if (alm.addons.elementor) {
12753-
// Elementor
12754-
return elementorGetContent(alm, ajaxurl, response, cache_slug);
12775+
return elementorGetContent(alm, url, response, cache_slug); // Elementor
1275512776
} else if (alm.addons.queryloop) {
12756-
// Query Loop
12757-
return queryLoopGetContent(alm, ajaxurl, response, cache_slug);
12777+
return queryLoopGetContent(alm, url, response, cache_slug); // Query Loop
1275812778
}
1275912779

12760-
// Standard ALM - Get data from response.
12761-
return response.data;
12780+
return response.data; // Standard ALM.
1276212781
})["catch"](function (error) {
12763-
// Error
1276412782
alm.AjaxLoadMore.error(error, 'adminajax');
1276512783
});
1276612784
case 6:
1276712785
data = _context2.sent;
1276812786
_context2.t0 = type;
12769-
_context2.next = _context2.t0 === 'standard' ? 10 : _context2.t0 === 'totalposts' ? 12 : _context2.t0 === 'totalpages' ? 12 : 14;
12787+
_context2.next = _context2.t0 === 'totalposts' ? 10 : _context2.t0 === 'totalpages' ? 10 : 12;
1277012788
break;
1277112789
case 10:
12772-
alm.AjaxLoadMore.render(data);
12773-
return _context2.abrupt("break", 14);
12774-
case 12:
1277512790
if (alm.addons.paging && alm.addons.nextpage && typeof almBuildPagination === 'function') {
1277612791
window.almBuildPagination(data.totalpages, alm);
1277712792
alm.totalpages = data.totalpages;
@@ -12781,6 +12796,9 @@ var isBlockEditor = document.body.classList.contains('wp-admin');
1278112796
}
1278212797
}
1278312798
return _context2.abrupt("break", 14);
12799+
case 12:
12800+
alm.AjaxLoadMore.render(data);
12801+
return _context2.abrupt("break", 14);
1278412802
case 14:
1278512803
case "end":
1278612804
return _context2.stop();
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array(), 'version' => 'e2b934a6b1ca87b301e0');
1+
<?php return array('dependencies' => array(), 'version' => '9af341a9172898f23fbd');

build/frontend/ajax-load-more.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/classes/class-alm-queryargs.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function alm_build_queryargs( $a, $is_ajax = true ) {
7272
$month = isset( $a['month'] ) ? $a['month'] : '';
7373
$day = isset( $a['day'] ) ? $a['day'] : '';
7474

75-
// Custom Fields.
75+
// Meta/Custom Fields.
7676
$sort_key = isset( $a['sort_key'] ) ? $a['sort_key'] : '';
7777
$meta_key = isset( $a['meta_key'] ) ? $a['meta_key'] : '';
7878
$meta_value = isset( $a['meta_value'] ) ? $a['meta_value'] : '';
@@ -85,6 +85,14 @@ public static function alm_build_queryargs( $a, $is_ajax = true ) {
8585
$meta_relation = isset( $a['meta_relation'] ) ? $a['meta_relation'] : '';
8686
$meta_relation = empty( $meta_relation ) || $facets ? 'AND' : $meta_relation;
8787

88+
// Date Query.
89+
$date_query = isset( $a['date_query'] ) ? $a['date_query'] : '';
90+
$date_query_before = isset( $a['date_query_before'] ) ? $a['date_query_before'] : '';
91+
$date_query_after = isset( $a['date_query_after'] ) ? $a['date_query_after'] : '';
92+
$date_query_inclusive = isset( $a['date_query_inclusive'] ) ? $a['date_query_inclusive'] : '';
93+
$date_query_compare = isset( $a['date_query_compare'] ) ? $a['date_query_compare'] : '';
94+
$date_query_relation = isset( $a['date_query_relation'] ) ? $a['date_query_relation'] : '';
95+
8896
// Search.
8997
$s = isset( $a['search'] ) ? $a['search'] : '';
9098

@@ -270,6 +278,27 @@ public static function alm_build_queryargs( $a, $is_ajax = true ) {
270278
}
271279
}
272280

281+
// Date Query.
282+
if ( $date_query || $date_query_after || $date_query_before ) {
283+
$args['date_query'] = [];
284+
if ( ! empty( $date_query_relation ) ) {
285+
$args['date_query']['relation'] = $date_query_relation;
286+
}
287+
if ( $date_query_compare ) {
288+
$args['date_query']['compare'] = $date_query_compare;
289+
}
290+
291+
// Standard Date Query.
292+
if ( $date_query ) {
293+
$args = alm_get_date_query( $date_query, $args );
294+
}
295+
296+
// Date Query (Before/After).
297+
if ( $date_query_before || $date_query_after ) {
298+
$args = alm_get_date_query_before_after( $args, $date_query_before, $date_query_after, $date_query_inclusive );
299+
}
300+
}
301+
273302
// Sort key.
274303
if ( ! empty( $sort_key ) && strpos( $orderby, 'meta_value' ) !== false ) {
275304
// Only order by sort_key, if `orderby` is set to meta_value{_num}.

core/classes/class-alm-shortcode.php

+24-6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public static function alm_render_shortcode( $atts ) {
7878
$atts = $default_atts ? array_merge( $default_atts, $atts ) : $atts;
7979

8080
// Extact shortcode arrtibutes to variables.
81-
// phpcs:disable
8281
extract(
8382
shortcode_atts(
8483
[
@@ -164,7 +163,7 @@ public static function alm_render_shortcode( $atts ) {
164163
'preloaded_amount' => '5',
165164
'seo' => 'false',
166165
'seo_offset' => false,
167-
'template' => '',
166+
'template' => '',
168167
'repeater' => 'default', // Deprecated
169168
'theme_repeater' => 'null', // Deprecated
170169
'cta' => false,
@@ -187,12 +186,18 @@ public static function alm_render_shortcode( $atts ) {
187186
'taxonomy_operator' => '',
188187
'taxonomy_relation' => '',
189188
'taxonomy_include_children' => '',
190-
'sort_key' => '',
189+
'sort_key' => '',
191190
'meta_key' => '',
192191
'meta_value' => '',
193192
'meta_compare' => '',
194193
'meta_relation' => '',
195194
'meta_type' => '',
195+
'date_query' => '',
196+
'date_query_before' => '',
197+
'date_query_after' => '',
198+
'date_query_compare' => '',
199+
'date_query_inclusive' => '',
200+
'date_query_relation' => '',
196201
'year' => '',
197202
'month' => '',
198203
'day' => '',
@@ -216,7 +221,7 @@ public static function alm_render_shortcode( $atts ) {
216221
'pause' => 'false',
217222
'destroy_after' => '',
218223
'transition' => 'fade',
219-
'transition_delay' => "0",
224+
'transition_delay' => '0',
220225
'transition_container_classes' => '',
221226
'masonry_selector' => '',
222227
'masonry_columnwidth' => '',
@@ -242,7 +247,7 @@ public static function alm_render_shortcode( $atts ) {
242247
'no_results_text' => '',
243248
'placeholder' => '',
244249
'lazy_images' => false,
245-
'urls' => 'true',
250+
'urls' => 'true',
246251
'archive' => false,
247252
'woocommerce' => false,
248253
'elementor' => false,
@@ -257,7 +262,6 @@ public static function alm_render_shortcode( $atts ) {
257262
$atts
258263
)
259264
);
260-
// phpcs:enable
261265

262266
$id = sanitize_key( $id );
263267
$vars = self::alm_strip_tags( $vars );
@@ -826,6 +830,12 @@ public static function alm_render_shortcode( $atts ) {
826830
'year' => $year,
827831
'month' => $month,
828832
'day' => $day,
833+
'date_query' => $date_query,
834+
'date_query_before' => $date_query_before,
835+
'date_query_after' => $date_query_after,
836+
'date_query_compare' => $date_query_compare,
837+
'date_query_inclusive' => $date_query_inclusive,
838+
'date_query_relation' => $date_query_relation,
829839
'author' => $author,
830840
'post__in' => $post__in,
831841
'post__not_in' => $post__not_in,
@@ -1179,6 +1189,14 @@ public static function alm_render_shortcode( $atts ) {
11791189
$ajaxloadmore .= $month ? ' data-month="' . esc_attr( $month ) . '"' : '';
11801190
$ajaxloadmore .= $day ? ' data-day="' . esc_attr( $day ) . '"' : '';
11811191

1192+
// Date Query.
1193+
$ajaxloadmore .= $date_query ? ' data-date-query="' . esc_attr( $date_query ) . '"' : '';
1194+
$ajaxloadmore .= $date_query_after ? ' data-date-query-after="' . esc_attr( $date_query_after ) . '"' : '';
1195+
$ajaxloadmore .= $date_query_before ? ' data-date-query-before="' . esc_attr( $date_query_before ) . '"' : '';
1196+
$ajaxloadmore .= $date_query_inclusive ? ' data-date-query-inclusive="' . esc_attr( $date_query_inclusive ) . '"' : '';
1197+
$ajaxloadmore .= $date_query_compare ? ' data-date-query-compare="' . esc_attr( $date_query_compare ) . '"' : '';
1198+
$ajaxloadmore .= $date_query_relation ? ' data-date-query-relation="' . esc_attr( $date_query_relation ) . '"' : '';
1199+
11821200
// Author.
11831201
$ajaxloadmore .= $author ? ' data-author="' . esc_attr( $author ) . '"' : '';
11841202

0 commit comments

Comments
 (0)