I have a single page where I want to make a pagination for a certain custom post type called ‘article’ and I’m also using a $_GET param called ‘week’.
Basically when I go to http://www.mydomain.com/single-page/?week=7 I want to see the pagination of my posts from ‘article’ post type with taxonomy called week equal to 7.
All it’s fine, but paginate_links function doesn’t act how I want. For example the 2 pagination link has this url http://www.mydomain.com/single-page/?week=7/page/2. But this url doesn’t work, it gives an 404 Error.
But this url http://www.mydomain.com/single-page/page/2/?week=7 it’s working. So what is the solution?
-
Is there a way to tell WordPress to use www.mydomain.com/single-page/page/2/?week=7 when I go to www.mydomain.com/single-page/?week=7/page/2 ?
-
Do you have some good tutorial for custom posts type pagination?
This is the code I’m using to paginate:
//The paginate function
function paginate_articles_week()
{
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$pagination = array(
'base' => @add_query_arg('page'),
'format' => '?page=%#%',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => true,
'type' => 'list',
'prev_text' => '«',
'next_text' => '»',
);
if ($wp_rewrite->using_permalinks())
$pagination['base'] = user_trailingslashit(trailingslashit(remove_query_arg('s', get_pagenum_link(1))) . 'page/%#%/', 'paged');
if (!empty($wp_query) && $pagination['total'] != 1) {
$pagination['add_args'] = array('s' => get_query_var('s'));
echo "<div class='paginate'><strong>Pagini:</strong>" . paginate_links($pagination) . "</div>";
}
}
//The page template
global $post;
$week = $_GET['week'];
$slug = 'week-' . $week . '-month-2';
$paged = 1;
$postsPerPage = 1;
if (get_query_var('paged')) { $paged = get_query_var('paged'); }
if (get_query_var('page')) { $paged = get_query_var('page'); }
$args = array(
'post_type'=> 'article',
'paged' => $paged,
'posts_per_page' => $postsPerPage,
'timeline' => $slug
);
query_posts($args);
{the loop}
paginate_articles_week();
Thanks in advance for the answers 🙂