Admin Panel WP PageNavi not working
-
For a long time i have been using WordPress PageNavi in the front end, but it turns out that the same code structure does not work on the back-end admin panel. Despite showing the pagination and clicking a page greater than 1, the content showed is always the first page. CSS styles are not being recognized neither, as it shows all the html without any style.
I have created an Admin panel section called ‘Reports’. The following is the code function triggered to that section:
function reportsAdmin(){ $args = array( 'post_type' => 'post', 'posts_per_page' => 2, 'order' => 'DESC', ); $query = new WP_Query($args); if($query->have_posts()){ echo '<table>'; echo '<thead><tr><th colspan="1">Name</th><th colspan="1">No. of reorts</th></tr></thead>'; while($query->have_posts()){ $query->the_post(); ?> <tr> <td><?php echo get_the_title(); ?></td> <td><?php echo get_post_meta(get_the_ID(), 'numberReports', true); ?></td> </tr> <?php } echo '</table>'; } else { echo 'No content.'; } wp_reset_postdata(); ?> <div class="navigation"><?php wp_pagenavi( array( 'query' => $query ) ); ?></div> <?php wp_reset_query(); }
Needless is to say that i have more than 2 posts. I need to repeat that i am using same structure on the front end and it does work. I am also doing it the standard wordpress way and it does not works neither:
function reportsAdmin(){ $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array( 'post_type' => 'post', 'posts_per_page' => 2, 'order' => 'DESC', 'paged' => $paged ); $query = new WP_Query($args); if($query->have_posts()){ echo '<table>'; echo '<thead><tr><th colspan="1">Name</th><th colspan="1">No. of reports</th></tr></thead>'; while($query->have_posts()){ $query->the_post(); ?> <tr> <td><?php echo get_the_title(); ?></td> <td><?php echo get_post_meta(get_the_ID(), 'numberReports', true); ?></td> </tr> <?php } echo '</table>'; ?> <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div> <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php } else { echo 'No content.'; } wp_reset_postdata(); }
I would thank any help.
- The topic ‘Admin Panel WP PageNavi not working’ is closed to new replies.