我已经为自定义post类型分页编写了代码,但它不起作用。下面是一些代码。
<?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>