CPT nav links
-
We are using the following to set the orderby to the slug (name) and on the archive page this is working fine.
In functions.php:
function custom_cpt_order($query) { if( is_admin() ) { return; } if(! $query->is_admin) { if ($query->get('post_type') == 'our_cpt') { $query->set('orderby', 'name'); $query->set('order', 'ASC'); } } return $query; } add_filter('pre_get_posts', 'custom_cpt_order');
The problem is in the single-cpt page where we want to also have the prev. or next post links use the same orderby of slug (name).
in single-cpt.php
if ( is_singular( 'attachment' ) ) { // Parent post navigation. the_post_navigation( array( 'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ), ) ); } elseif ( is_singular( 'our_cpt' ) ) { // Previous/next post navigation. the_post_navigation( array( 'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next CPT in List', 'twentysixteen' ) . '</span> ' . '<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' . '<span class="post-title">%title</span>', 'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous CPT in List', 'twentysixteen' ) . '</span> ' . '<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' . '<span class="post-title">%title</span>', ) ); }
The next prev posts are using the default of DATE and DESC.
I have reviewed the docs, researched several well known sites and forums and find little if anything on the right way to do this.
Working examples (code) greatly appreciated. Thanks!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘CPT nav links’ is closed to new replies.