previous_post_link/next_post_link not putting all posts in order
-
I have inherited a site and the previous developer has created a post type. On the main page for this post type there is a list of all the businesses which is listed in the correct order. when you click on one of the businesses it opens a page that gives a summary of each business. At the top of each one of these pages is where the previous_post_link/previous_post_link are located. The issue is that there are about half a dozen of these businesses that are out of order, they are being placed either at the beginning or at the end. Also note that I created a brand new post to test and it to was placed at the end, out of order.
I had thought that perhaps the taxonomy was incorrect and that multiple categories are being used and that was causing the issue so I found something that I thought might help but alas it did not.**single.php**
<div class="container_16 nested" id="post-nav-links"> <?php $mam_global_stay_in_cat = ($_GET['stayincat']) ? $_GET['stayincat'] : false; if ( $mam_global_stay_in_cat ) { ?> <div class="col_8 post-nav-button"><p>Previous:</p><?php previous_post_link('? %link','%title',true) ?></div> <div class="col_8 post-nav-button"><p>Next:</p><?php previous_post_link('%link ?','%title',true) ?></div> <?php } else { ?> <div class="col_8 post-nav-button"><p>Previous:</p><?php previous_post_link('? %link') ?></div> <div class="col_8 post-nav-button"><p>Next:</p><?php next_post_link('%link ?') ?></div> <?php } ?> </div>
**functions.php**
function mam_get_previous_post_join_filter ( $join, $in_same_cat = false, $excluded_categories = '' ) { global $mam_global_stay_in_cat; if ($mam_global_stay_in_cat) { $join = preg_replace('/tt.term_id IN \([^(]+\)/',"tt.term_id IN ($mam_global_stay_in_cat)",$join); } return $join; } function mam_get_next_post_join_filter ( $join, $in_same_cat = false, $excluded_categories = '' ) { global $mam_global_stay_in_cat; if ($mam_global_stay_in_cat) { $join = preg_replace('/tt.term_id IN \([^(]+\)/',"tt.term_id IN ($mam_global_stay_in_cat)",$join); } return $join; } function mam_previous_post_link_filter ($link='') { global $mam_global_stay_in_cat; if ($mam_global_stay_in_cat && $link) { $link = mam_add_query_arg('stayincat',$mam_global_stay_in_cat,$link); } return $link; } function mam_next_post_link_filter ($link='') { global $mam_global_stay_in_cat; if ($mam_global_stay_in_cat && $link) { $link = mam_add_query_arg('stayincat',$mam_global_stay_in_cat,$link); } return $link; } function mam_add_query_arg ($key,$value,$link) { if (strpos($link,'href')) { $hrefpat = '/(href *= *([\"\']?)([^\"\' ]+)\2)/'; } else { $hrefpat = '/(([\"\']?)(http([^\"\' ]+))\2)/'; } if (preg_match($hrefpat,$link,$matches)) { $url = $matches[3]; $newurl = add_query_arg($key,$value,$url); $link = str_replace($url,$newurl,$link); } return $link; } add_filter('get_previous_post_join','mam_get_previous_post_join_filter'); add_filter('get_next_post_join','mam_get_next_post_join_filter'); add_filter('previous_post_link','mam_previous_post_link_filter'); add_filter('next_post_link','mam_next_post_link_filter'); **Post_type** register_post_type('posts_firms', array( 'label' => 'Member Firms', 'description' => '', 'menu_icon' => 'dashicons-groups', 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => true, 'rewrite' => array( 'slug' =>'firms'), 'query_var' => true, 'supports' => array( 'title', 'editor', 'excerpt', 'post-formats') ) ); **taxonomy** register_taxonomy( 'cities', 'posts_firms', $args ); $labels = array( 'name' => _x( 'Branches', 'taxonomy general name' ), 'singular_name' => _x( 'Branch', 'taxonomy singular name' ), 'menu_name' => __( 'Branches' ), 'search_items' => __( 'Search Branches' ), 'all_items' => __( 'All Branches' ), 'parent_item' => __( 'Parent Branch' ), 'parent_item_colon' => __( 'Parent Branch:' ), 'edit_item' => __( 'Edit Branches' ), 'update_item' => __( 'Update Branches' ), 'add_new_item' => __( 'Add New Branch' ), 'new_item_name' => __( 'New Branch Name' ), ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'branch' ), ); register_taxonomy( 'branches', 'posts_firms', $args ); $labels = array( 'name' => _x( 'Country', 'taxonomy general name' ), 'singular_name' => _x( 'Country', 'taxonomy singular name' ), 'menu_name' => __( 'Country' ), 'search_items' => __( 'Search Countries' ), 'all_items' => __( 'All Countries' ), 'parent_item' => __( 'Parent Country' ), 'parent_item_colon' => __( 'Parent Country:' ), 'edit_item' => __( 'Edit Countries' ), 'update_item' => __( 'Update Branches' ), 'add_new_item' => __( 'Add New Country' ), 'new_item_name' => __( 'New Country Name' ), ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'country' ), ); register_taxonomy( 'countries', 'posts_firms', $args ); $labels = array( 'name' => _x( 'Regions', 'taxonomy general name' ), 'singular_name' => _x( 'Region', 'taxonomy singular name' ), 'menu_name' => __( 'Regions' ), 'search_items' => __( 'Search Regions' ), 'all_items' => __( 'All Regions' ), 'parent_item' => __( 'Parent Region' ), 'parent_item_colon' => __( 'Parent Region:' ), 'edit_item' => __( 'Edit Regions' ), 'update_item' => __( 'Update Regions' ), 'add_new_item' => __( 'Add New Region' ), 'new_item_name' => __( 'New Region Name' ), ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'region' ), );
I will be more than glad to supply anything else that would be needed. I am really stuck on this strange issue. Thanks in advance. BTW this is a custom site.
The site is interlaw.org issue is in members>find by list>the individual firms is where the previous and next links are.
- The topic ‘previous_post_link/next_post_link not putting all posts in order’ is closed to new replies.