• We’re inside of a custom post type. We’ve tried inside the loop and outside the loop.

    If we do something like this: https://gist.github.com/grok/0bc7ef756888da518e88

    We’ll have like 15 IDs we expect to cycle through… it will loop through 2 or 3 of them.

    We deactivate the plugin, this problem goes away. With the plugin activated, all next posts end up being id 671 — when next SHOULD be something like 1061.

    Another example:

    We are on 1061, next is back to being 671. BUT according to the plugin, the next one should be 1037.

    So on a hunch, I went back to the plugin, changed the order…and see if that fixed it…nope.

    The order now goes like this:

    1. 671
    2. 969
    3. 666
    4. 671 << THIS SHOULD BE 660

    Anyway — this fundamental breakage in core functionality will mean we have to deactivate the plugin.

    https://www.ads-software.com/plugins/post-types-order/

Viewing 1 replies (of 1 total)
  • I encountered a similar error, where parameters to previous_post_link were ignored. I traced it to the following filters in post-type-order.php:

    add_filter('get_previous_post_where', 'cpto_get_previous_post_where', 10, 3);
    add_filter('get_previous_post_sort', 'cpto_get_previous_post_sort');
    add_filter('get_next_post_where', 'cpto_get_next_post_where', 10, 3);
    add_filter('get_next_post_sort', 'cpto_get_next_post_sort');

    I added the extra parameters “10, 3”, they are needed to get extra information.

    After that the functions “cpto_get_previous_post_where” and “cpto_get_next_post_where” need some fixes to support arrays for $excluded_categories. I copied code from wordpress original ‘get_adjacent_post’ function

    if (isset($in_same_cat))
            if ( $in_same_cat || !empty($excluded_categories) )
                {
                    $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
    
    		if ( $in_same_cat ) {
    			if ( ! is_object_in_taxonomy( $post->post_type, 'category' ) )
    				return '';
    			$cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
    			if ( ! $cat_array || is_wp_error( $cat_array ) )
    				return '';
    			$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
    		}
    
    		$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
    		if ( ! empty( $excluded_categories ) ) {
    			if ( ! is_array( $excluded_categories ) ) {
    				// back-compat, $excluded_categories used to be IDs separated by " and "
    				if ( strpos( $excluded_categories, ' and ' ) !== false ) {
    					_deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded categories.' ), "'and'" ) );
    					$excluded_categories = explode( ' and ', $excluded_categories );
    				} else {
    					$excluded_categories = explode( ',', $excluded_categories );
    				}
    			}
    
    			$excluded_categories = array_map( 'intval', $excluded_categories );
    
    			if ( ! empty( $cat_array ) ) {
    				$excluded_categories = array_diff($excluded_categories, $cat_array);
    				$posts_in_ex_cats_sql = '';
    			}
    
    			if ( !empty($excluded_categories) ) {
    				$posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
    			}
    		}
                }

    I hope that the plugin can be fixed with this information.

Viewing 1 replies (of 1 total)
  • The topic ‘get_next_post() breaking’ is closed to new replies.