Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#29565 closed defect (bug) (duplicate)

get_adjacent_post() not excluding category after upgrade (3.9.2 -> 4.0)

Reported by: toynn's profile toyNN Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.0
Component: Taxonomy Keywords:
Focuses: template Cc:

Description

Code works fine in 3.9.2 but category (posts) not excluded after upgrade to 4.0

$post = get_adjacent_post(false, '410', false);

or

$post = get_adjacent_post(false, '31 and 32 and 410', false);

I've overwritten only the v4.0 "link-template.php" with the file from v3.9.2 and properly exclude the post category(s) again.

Full custom function I've been using,

function comtrya_get_next_post_float() {
	$post = get_adjacent_post(false, '410', false);
	if (!$post) return;
	$thumb_nav = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'facebook');
	echo '<a href="'.get_permalink($post).'" rel="next" class="older" title="'.get_the_title($post).'">';
	echo '<p>'.htmlspecialchars(substr_replace(html_entity_decode(htmlspecialchars_decode(get_the_title($post)),0,'UTF-8'),'..',27,1000)).'</p>';
	echo '<img height="80" width="80" class="nav-thumbnail" src="'.$thumb_nav[0].'">';
	echo '<span class="cfb_next"></span>';
	echo '</a>';
}

Change History (5)

#1 @toyNN
9 years ago

Tried re-writing my call to get_adjacent_posts to pass array of catagory IDs to exclude at same result of it not excluding when using v4.0.0 link-template.php and excludes properly with v3.9.2 link-template.php

function comtrya_get_next_post_float() {
	$post = get_adjacent_post(false, array(31,410), false);
	if (!$post) return;
	$thumb_nav = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'facebook');
	echo '<a href="'.get_permalink($post).'" rel="next" class="older" title="'.get_the_title($post).'">';
	echo '<p>'.htmlspecialchars(substr_replace(html_entity_decode(htmlspecialchars_decode(get_the_title($post)),0,'UTF-8'),'..',27,1000)).'</p>';
	echo '<img height="80" width="80" class="nav-thumbnail" src="'.$thumb_nav[0].'">';
	echo '<span class="cfb_next"></span>';
	echo '</a>';
}

Comparing the function get_adjacent_post() looks like it was extensively re-written in v4.0.0 so not easy to see why its not working now...atleast for me.

#2 @toyNN
9 years ago

I isolated the problem (atleast as I see it) to this new code (commented out) in the v4.0.0 get_adjacent_post() function. I replaced with the v3.9.2 code and the get_adjacent_post() correctly excludes the category ids (array),

if ( ! empty( $excluded_terms ) ) {
     /* $where .= " AND p.ID NOT IN ( SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . implode( $excluded_terms, ',' ) . ') )'; */
	$where = $wpdb->prepare( " AND tt.taxonomy = %s AND tt.term_id NOT IN (" . implode( $excluded_terms, ',' ) . ')', $taxonomy );
}

#3 @DrewAPicture
9 years ago

  • Component changed from General to Posts, Post Types
  • Focuses template added

#4 @toyNN
9 years ago

This issue appears to be fixed now in v4.0.1. The noted code spot in the function get_adjacent_post() has new query code that appears to properly exclude categories when requesting adjacent posts.

#5 @ocean90
9 years ago

  • Component changed from Posts, Post Types to Taxonomy
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #29663.

Note: See TracTickets for help on using tickets.