I have created 9 different Custom Post Types via ACF and an assortment of custom field blocks for 8 of them. Those 8 are used to create different content, based on requirements for each post type. The 9th one (titled: "Resources"), I created simply to be an archive repository for ALL of the posts that have been built. Every post created has been assigned to categories created in the categories archive. The individual post archives are functioning just fine. The posts are showing, sorting as desired AND the pagination is working on each.
For the Resources archive, my requirements are to:
- Combine all the post types into 1 "Resources" archive (completed).
- Sort the posts on the "Resources" archive by their publish dates (completed).
- Be able to filter these posts based on their categories - using drop down selectors (not completed).
Issue #1:
- My pagination is not working - it doesn't show on the page at all. The row is in the source code, but the functions are missing. This pagination works with my other archive pages, so, I'm not sure why this one is refusing to work.
Currently, there are 41 total posts. There will be lots more. By changing the "posts_per_page" to "41" or say a ridiculous number like "50" or "60", all of the posts show up, sorted by publish date, as expected.
However, when keeping the number at "20" per page, the pagination code does not display.
Issue #2:
- I have no idea how to filter the combined posts by the categories they've been assigned.
My template code is below:
<div id="primary" class="content-area">
<main id="main" class="site-main">
<div class="container resources">
<?php
$cptArgs = [
'post_type' => array(
'blogs',
'case-study',
'datasheet',
'event',
'in-the-news',
'press-release',
'video',
'webinar'
),
'posts_per_page' => 20,
'paged' => get_query_var( 'paged' ),
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'OR',
'cpt_date_field' => array(
'key' => 'CPT_Images_published-date',
'type' => 'DATE'
),
'article_date_field' => array(
'key' => 'article_date',
'type' => 'DATE'
),
'event_date_field' => array(
'key' => 'event_specific_data_event_date_start',
'type' => 'DATE'
),
'case_study_date_field' => array(
'key' => 'CPT_cs_hero_section_CPT_Images_published-date',
'type' => 'DATE'
)
),
'orderby' => array(
'cpt_date_field' => 'DESC',
'case_study_date_field' => 'DESC',
'article_date_field' => 'DESC',
'event_date_field' => 'DESC',
),
];
$cptQuery = new WP_Query($cptArgs);
?>
<?php if ( $cptQuery ) { ?>
<div class="row">
<form id="filterCPT">
<div class="row">
<div class="col-3 col-md-3 col-sm-3">
</div>
<div class="col-3 col-md-3 col-sm-3">
<select name="marketFilter" id="marketFilter">
<option label="- Filter By Market -">
<option value="retail-agency">Retail Agency</option>
<option value="mga">MGA</option>
<option value="wholesaler">Wholesaler</option>
<option value="carrier">Carrier</option>
</select>
</div>
<div class="col-3 col-md-3 col-sm-3">
<select name="cptFilter" id="cptFilter">
<option label="- Filter By Content Type -">
<option value="blogs">Blogs</option>
<option value="case-studies">Case Studies</option>
<option value="datasheets">Datasheets</option>
<option value="events">Events</option>
<option value="in-the-news">In The News</option>
<option value="press-releases">Press Releases</option>
<option value="videos">Videos</option>
<option value="webinars">Webinars</option>
</select>
</div>
<div class="col-3 col-md-3 col-sm-3">
</div>
</div>
</form>
<script>
$('form#filterCPT select').on('change', function(){
$(this).closest('form').submit();
});
</script>
</div>
<div class="row row-cols-1 row-cols-md-3 g-4 cardLayout">
<?php while ( $cptQuery->have_posts() ) : $cptQuery->the_post();
setup_postdata( $cptQuery );
include( get_stylesheet_directory() . '/template-parts/vars-cpt-resources.php');
?>
<div class="col-3 col-md-3 col-sm-3 notFeatured">
<div class="card h-100">
<span class="cardImgWrap" role="img" aria-label="<?php echo $thumbDesc; ?>">
<img class="card-img-top" src="<?php echo $thumbUrl; ?>" alt="<?php echo $thumbAlt; ?>" title="<?php echo $thumbTitle; ?>" />
</span>
<div class="card-body">
<h5 class="card-title"><?php echo $h1Copy; ?></h5>
<p class="card-text"><?php echo $excerpt; ?></s>
</div>
<a class="ctaButton clickTrackCTAButton blogs" href="<?php the_permalink();?>" title="<?php echo $h1Copy; ?>">
<?php echo $ctaButtonIcon; ?><?php echo $ctaButtonTitle; ?>
</a>
</div>
</div>
<?php endwhile; ?>
</div> <!-- row -->
<div class="row pagination">
<div class="col-12 col-md-12 col-sm-12 paginationRow">
<?php
the_posts_pagination( array(
'mid_size' => 3,
'prev_text' => _( 'Previous Page' ),
'next_text' => _( 'Next Page' ),
) );
?>
</div>
</div>
<?php wp_reset_postdata(); ?>
<?php } else { ?>
<?php echo esc_html__( 'No posts matching the query were found.', 'your-translate-domain' ); ?>
<?php } ?>
<?php if ($aboutPatra): ?>
<?php include( get_stylesheet_directory() . '/template-parts/inc-block_about-patra.php'); ?>
<?php endif; ?>
</div><!-- #container -->
</main><!-- #main -->
</div><!-- #primary -->
Any assistance in getting the pagination to function and recommendations to perform the category filtering (either through custom development OR an acceptable plugin that won't blow up my site) would be greatly appreciated.
I've tried several different ways of implementing the pagination - including using filtering scripts I found online written into the functions.php. I've even tried moving the resources archive shown here from a "custom post type" to a "page". And that obviously did not work. I've even tried a couple of pagination plugins. They did not work.
At this point I'm not sure what to do to get the pagination functioning.
As for the filtering by category, I've looked for plugins to create the function I'm looking for, and have had no luck. I'm not having much luck in sourcing the answers via the Codex or Google either.