I will preserve this quick. I am new to PHP and having a tough time understanding one of the best pagination practices for WP_Query.
(I have gotten pagination working, however solely by posts_per_page
.)
Naturally I might prefer to paginate by a customized date area, however being unable to take action, have opted to $_GET parameters to vary the meta_query_args
second array key worth to date('Ymt', strtotime('+1 month'))
$meta_query_args = [
[
'key' => 'starting_date',
'value' => date('Ymd',strtotime("today")),
'compare' => '>',
],
[
'key' => 'ending_date',
'value' => date('Ymt', strtotime('this month')), // This changes to ('+1 month')
'compare' => '<=',
]
];
$args = array(
'post_type' => 'publish',
'posts_per_page' => -1,
'category_name' => '',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key' => 'starting_date',
'meta_query' => $meta_query_args,
'paged' => $paged,
);
// Button appends $_GET
if (isset($_GET['next_month'])) {
$meta_query_args[1]['value'] = date('Ymt', strtotime('+1 month'));
}
After all, this solely works as soon as. Is there a approach to retailer the worth elsewhere for incrementing? Or actually paginate by customized fields? (Or extra like meta queries I might say).
I’ve performed hours of analysis, however really feel I am nonetheless lacking one thing. Possibly utilizing pre_get_posts
? I want an excellent kick in the appropriate path. I am feeling fairly defeated. Trying ahead to your steering, cheers.