We have a page on one of our websites which outputs a WP Query loop of data with a custom post type we have setup within ACF called "Client Stories". In our WP Query we’re also using the page navigation numbers so you can go to page 2, 3 etc.
Everything works perfectly, the post type works and the page links to the next/prev pages too.
However, one thing we’d like to change is the URL structure which we can see under Advanced Settings > URLs. We’d like to change it from the default post type key which is "client-story" to a custom permalink called "client-stories".
When we enter this custom permalink URL the WP Query still works absolutely fine and bring through the data and the URL has successfully changed, however the page numbers navigation stops working and we get a 404 – Page Not Found error when trying to click on page 2 etc.
We’d like the URL to be /client-stories/story-1/ instead of /client-story/story-1/ but unsure how to do it without breaking the page number navigation.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'client-story',
'post_status' => 'publish',
'posts_per_page' => 9,
'paged' => $paged,
);
$loop = new WP_Query($args);
$total_pages = $loop->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo '<div class="pagination_wrapper">';
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('Prev'),
'next_text' => __('Next'),
));
echo '</div>';
}
2
Answers
It should be helpful.