I have a custom query that can a list that can be up to around 20 items, so it needs pagination. It is displaying the correct amount of pages for how many items, but when clicking it it refreshes and the printed page number doesn't change from 1->2. I watched this video and this documentation. but have just been spinning my wheels. This loop is part of a single-item page and we are using the Tainacan theme, which gets really frustrating to work with. This question is outside of the theme, it is just for context.
$postType = get_post_type();
$dynamicValue = get_post_meta(get_the_ID(), '3870', true);
// Remove the last characters "%.mp3" from the dynamic value
$dynamicValue = substr($dynamicValue, 0, -6);
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array(
'post_type' => array($postType),
'meta_query' => array(
array(
'key' => '3870',
'value' => $dynamicValue,
'compare' => 'LIKE',
)
),
'orderby' => 'meta_value',
'meta_key' => '3870',
'order' => 'ASC',
'posts_per_page' => 10, // Number of items to display per page
'paged' => get_query_var('paged'),
);
$query = new WP_Query($args);
if ($query->have_posts()) {
echo '<div>' . __('<table class="tg-wrap", id="recordingTracks"> ', 'tainacan-interface');
echo '<thead><tr><th colspan="2">Tracks from this segment</th></tr></thead><tbody>';
$part_number = 1;
while ($query->have_posts()) {
$query->the_post();
$meta_print_value = get_post_meta(get_the_ID(), '3870', true);
$trackNum = substr($meta_print_value, -6, -4);
$trackNumNumbersOnly = preg_replace('/[^0-9]/', '', $trackNum); // Strip out letters
$highlightClass = ($sessionId == $meta_print_value) ? 'highlight' : ''; // Check if it matches the session ID
?>
<tr>
<td class="<?php echo $highlightClass; ?>"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></td>
<td>Track <?php echo $part_number; ?></td>
<td><?php echo ($meta_print_value); ?></td>
</tr>
<?php
$part_number++;
}
echo '</tbody></table></div>';
**echo $paged;
echo '<br/>------------------<br/>';
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?page=%#%',
'current' => get_query_var( 'paged') ,
'total' => $query->max_num_pages
));**
} else {
// No posts found
}
wp_reset_postdata();
}
//end if session exists
// If all three are false, print the metadata
if (!$recordingSessionExists && !$sessionExists && !$communitiesExists) {
echo 'Metadata:<br>';
echo '<pre>';
print_r($data->metadata);
echo '</pre>';
}
}