I have coded for custom post type pagination but it doesn't work. Here is some code for it.
<?php
global $wpdb;
$userid = get_current_user_id();
$userData = get_user_meta($userid , 'referat', true);
$args = array(
'post_type' => 'zt_lawyersportal',
'posts_per_page' => 2,
'orderby' => 'modified',
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
'meta_query' => array(
array(
'key' => 'referat',
'value' => $userData,
'compare' => 'IN',
),
),
);
$resData = new WP_Query($args); ?>
<div class="post">
<h2>Posteingang</h2>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>postname</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody id="dahboard-tbody">
<?php
if ($resData->have_posts()) :
while ($resData->have_posts()) :
$resData->the_post();
?>
<tr onclick="location.href = '<?= get_permalink(); ?>';" data-rowid="<?= $post->ID; ?>">
<td><?= get_the_title(); ?></td>
<td class="last">
<a class="green" href="<?= get_permalink($post->ID) ?>">Fall anzeigen</a>
</td>
</tr>
<?php
endwhile;
else:
echo '<tr><td><h2>Keine Fälle gefunden<h2></td></tr>';
endif;
wp_reset_postdata();
?>
</tbody>
</table>
<div class="col-sm-12">
<?php
$total_pages = $resData->max_num_pages;
if ($total_pages > 1) {
$current_page = max(1, get_query_var('paged'));
$page = paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('Prev'),
'next_text' => __('Next'),
'type' => 'array'
));
echo '<nav aria-label="Page navigation example"><ul class="pagination">';
foreach ($page as $key => $value) {
echo '<li class="page-item">' . $value . '</li>';
}
echo '</ul></nav>';
}
?>
</div>
</div>
I have coded for custom post type pagination but it doesn't work. Here is some code for it.
<?php
global $wpdb;
$userid = get_current_user_id();
$userData = get_user_meta($userid , 'referat', true);
$args = array(
'post_type' => 'zt_lawyersportal',
'posts_per_page' => 2,
'orderby' => 'modified',
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
'meta_query' => array(
array(
'key' => 'referat',
'value' => $userData,
'compare' => 'IN',
),
),
);
$resData = new WP_Query($args); ?>
<div class="post">
<h2>Posteingang</h2>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>postname</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody id="dahboard-tbody">
<?php
if ($resData->have_posts()) :
while ($resData->have_posts()) :
$resData->the_post();
?>
<tr onclick="location.href = '<?= get_permalink(); ?>';" data-rowid="<?= $post->ID; ?>">
<td><?= get_the_title(); ?></td>
<td class="last">
<a class="green" href="<?= get_permalink($post->ID) ?>">Fall anzeigen</a>
</td>
</tr>
<?php
endwhile;
else:
echo '<tr><td><h2>Keine Fälle gefunden<h2></td></tr>';
endif;
wp_reset_postdata();
?>
</tbody>
</table>
<div class="col-sm-12">
<?php
$total_pages = $resData->max_num_pages;
if ($total_pages > 1) {
$current_page = max(1, get_query_var('paged'));
$page = paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('Prev'),
'next_text' => __('Next'),
'type' => 'array'
));
echo '<nav aria-label="Page navigation example"><ul class="pagination">';
foreach ($page as $key => $value) {
echo '<li class="page-item">' . $value . '</li>';
}
echo '</ul></nav>';
}
?>
</div>
</div>
Share
Improve this question
edited Nov 4, 2019 at 8:44
Jacob Peattie
44.2k10 gold badges50 silver badges64 bronze badges
asked Nov 4, 2019 at 6:31
ShadowShadow
685 bronze badges
1 Answer
Reset to default -2The easiest way to have page nav for the custom post is to use WP PageNavi. After activating this plugin you need to add the following code in your custom post template.
<?php
if(function_exists('wp_pagenavi')) {
wp_pagenavi( array(
'query' =>$loop
));
}