- This topic is empty.
-
AuthorPosts
-
May 17, 2014 at 4:44 pm #170505
deeve007
ParticipantI have a Custom Post Type created where I have basic listing and pagination working fine as per this code more or less: https://css-tricks.com/snippets/wordpress/paginate-custom-post-types/
The problem comes about when I add this filter for what posts to display, which checked an Advanced Custom Fields field I have attached to the CPT:
$myargs = array ( 'post_type' => 'projects', 'paged' => $paged, 'meta_key' => 'archive_item', 'meta_value' => 'No' );
The relevant posts are excluded from displaying, however the pagination acts as if they’re still there, so for example if each page is set to show 5 posts, then even if only 5 posts are displaying as per the meta_key stipulated, pagination still links to a second page, where no posts are displayed.
Anyone know how to fix this?
(or if my description isn’t clear please let me know)May 18, 2014 at 11:23 pm #170572chrisburton
ParticipantI don’t use WP but have you solved this or still need help?
May 19, 2014 at 8:15 am #170599deeve007
ParticipantNope, if I’d solved it I would come back and post the solution.
May 19, 2014 at 11:00 am #170606chrisburton
Participant@deeve007 Well, did you try the
archives-{post-type-name}.php
method?May 19, 2014 at 11:04 am #170607deeve007
ParticipantThe post types are all set up to display using relevant templates for both the archives and the single posts. The issue is that the pagination is not able to recognise the correct number of items the loop has returned via the arguments used.
May 19, 2014 at 11:18 am #170608chrisburton
ParticipantCan I see your CPT loop?
May 19, 2014 at 12:31 pm #170613deeve007
Participant<?php // Loop filtering by ACF field wp_reset_postdata(); $myargs = array ( 'post_type' => 'consultations', 'paged' => $paged, 'orderby' => 'title', 'order' => 'ASC', 'meta_key' => 'archive_item', 'meta_value' => 'No' ); $myquery = new WP_Query($myargs); if($myquery->have_posts() ) : while($myquery->have_posts() ) : $myquery->the_post(); ?> <!-- Do you html stuff here --> <?php endwhile; endif; wp_reset_postdata(); ?> <?php if (show_posts_nav()) : ?> <?php if ( get_previous_posts_link() ) { ?> <span><?php previous_posts_link('« Newer consultations') ?></span> <?php } ?> <?php if ( get_next_posts_link() ) { ?> <span><?php next_posts_link('Older consultations »') ?></span> <?php } ?> <?php endif; ?>
May 19, 2014 at 1:03 pm #170614chrisburton
ParticipantWhere is
$paged
coming from?May 19, 2014 at 1:06 pm #170615deeve007
ParticipantIt’s an inbuilt variable in WordPress.
May 19, 2014 at 1:09 pm #170616chrisburton
ParticipantWhat is annoying is that this seems to be a common issue but at the same time there are so many different answers around the web.
May 19, 2014 at 1:25 pm #170617deeve007
ParticipantI haven’t found one that makes sense and/or works as yet.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.