Pagination for custom post type

[ad_1]

​

The loop I have for custom post type:

function unblock_peiblog_styles()
{

$unblock_blog_style = apply_filters(‘unblock_blog_style’, get_theme_mod(‘unblock_blog_style’, ‘classic-right’));

$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;

$args = array(
“post_type” => “event”,
‘posts_per_page’ => 2,
‘paged’ => $paged,
);

$peiCorner = new WP_Query($args);

// Start
if ($peiCorner->have_posts()) :

switch (esc_attr($unblock_blog_style)) {

case “list”:
echo ‘<div class=”column-wrapper blog-list”>’;
while ($peiCorner->have_posts()) : $peiCorner->the_post();
// Get the post summary
get_template_part(‘template-parts/content/content’, $unblock_blog_style !== ‘classic-right’ ? $unblock_blog_style : ”);
endwhile;
echo ‘</div>’;
// Blog navigation
unblock_peipaging_nav();
break;

case “classic-left”:
echo ‘<div class=”row column-wrapper blog-list”><div class=”col-md-8 order-md-2″>’;
while ($peiCorner->have_posts()) : $peiCorner-> the_post();
// Get the post summary
get_template_part(‘template-parts/content/content’, $unblock_blog_style !== ‘classic-right’ ? $unblock_blog_style : ”);
endwhile;
echo ‘</div><aside id=”left-sidebar” class=”col-md-4 order-2 order-md-1″>’;
get_sidebar();
echo ‘</aside></div>’;

// Blog navigation
unblock_peipaging_nav();
break;

Then this is the function i have for pagination:

function unblock_peipaging_nav()
{
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;

$args = array(
“post_type” => “event”,
‘posts_per_page’ => 2,
‘paged’ => $paged,
);

$peiCorner = new WP_Query($args);

echo “<nav class=’pagination’><div class=’nav-links’>”;
echo paginate_links(array(
‘base’ => get_pagenum_link(1) . ‘%_%’,
‘format’ => ‘%#%’,
‘current’ => $paged,
“total” => $peiCorner-> max_num_pages,
‘prev_text’ => is_rtl() ? ‘<i class=”bi bi-caret-right-fill”></i>’ : ‘<i class=”bi bi-caret-left-fill”></i>’,
‘next_text’ => is_rtl() ? ‘<i class=”bi bi-caret-left-fill”></i>’ : ‘<i class=”bi bi-caret-right-fill”></i>’,
‘before_page_number’ => ”
));
echo “</nav></div>”;
}

This is kind of what i pieced together from looking at google, but it’s not working properly. What is this `paged` variable exactly? I can’t get a definition of it. Then not really sure what `base`, `format` and `current` also do. Guess I must have the wrong values because the pagination shows but the pages are not updating properly.

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer