Paginating by year with date in custom field
I have inherited a WordPress based site and I’m trying to make some requested modifications, though I’m very new to the WordPress platform.
I currently have a Custom Page Template for a custom post type (“Seminar”). Seminars have a field called
_semdatethat represents the date of the Seminar in
The Custom Page Template originally listed the posts in chronological order by
_semdate, paginated with 5 posts per page. What I would like to do is instead have the posts paginated by year, where the year is defined from this
_semdatevariable, not from the date the post was actually made; ideally, so that users could visit the paginated page as /seminar/page/2013 (for example).
Is it possible to use built-in pagination functionality (either from WordPress or a plugin) with the pagination based on the year extracted from a string in a custom field? Or will I need to somehow “roll my own” pagination code?
What I expect are relevant parts of my Custom Page Template are below:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'seminar', 'date_pagination_type' => 'yearly', 'paged'=> $paged, 'meta_key'=>'_semdate', 'orderby' => 'meta_value', 'order' => 'DESC' ); $loop = new WP_Query($args); ?> <?php if ($loop->have_posts()) : ?> <h2><?php echo km_dp_get_current_date_label('Y', $loop); ?></h2> <?php while ($loop->have_posts()) : $loop->the_post(); $sem_date = get_post_meta( get_the_ID(), '_semdate', true); // more loop stuff ?> <?php endwhile; ?> <!-- pagination --> // ... variable stuff <?php next_posts_link($next_label, $loop->max_num_pages) ?> <?php previous_posts_link($prev_label, $loop->max_num_pages) ?>
- The topic ‘Paginating by year with date in custom field’ is closed to new replies.