WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#33211 closed defect (bug) (worksforme)

get_adjacent_post is not working with post_format

Reported by: valendesigns Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords: needs-unit-tests
Focuses: template Cc:

Description

When I was creating a custom post navigation function today for a client with WP 4.2.3, specifically for post formats, I noticed that the following does not return adjacent posts, even though they exist. I'm not sure if this has ever worked or is a regression. Has anyone been successful in using get_adjacent_post with post_format?

$prev = get_adjacent_post( true, '', true, 'post_format' );
$next = get_adjacent_post( true, '', false, 'post_format' );

Change History (5)

#1 @SergeyBiryukov
6 years ago

Just tested, and it only works for posts that actually have a format other than Standard (otherwise they're not connected to any term from the post_format taxonomy).

#2 follow-up: @valendesigns
6 years ago

Thank you for testing. Unfortunately, these post have non-standard formats. They are video, audio, & image formats with more than one in each term. None of them are finding adjacent posts for either previous or next. Could you briefly describe how you tested the issue?

#3 in reply to: ↑ 2 @SergeyBiryukov
6 years ago

Replying to valendesigns:

Could you briefly describe how you tested the issue?

I've created two asides, added your snippet to single.php, and checked the values of $prev and $next.

$next contained Aside 2 when viewing Aside 1, and $prev contained Aside 1 when viewing Aside 2.

Last edited 6 years ago by SergeyBiryukov (previous) (diff)

#4 @valendesigns
6 years ago

  • Keywords needs-patch removed

I guess I have to look deeper into this clients plugins and see if there's a conflict somewhere. Yay! At any rate we should have coverage here, the tests for get_adjacent_post are not covering all core taxonomies and they probably should be.

#5 @valendesigns
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I'll open a ticket for the unit tests later. I found the issue in my clients theme, which is an old one I didn't create and has loads of code. It seems to have a filter on get_previous_post_where & get_next_post_where that removes the post_format taxonomy from the query. I was able to bypass and everything it working correctly. I guess I should have dug deeper earlier. Thanks for verifying that it does work.

Note: See TracTickets for help on using tickets.