Skip to content

Instantly share code, notes, and snippets.

@aaronpeterson
Last active June 12, 2018 19:04
Show Gist options
  • Save aaronpeterson/9637291 to your computer and use it in GitHub Desktop.
Save aaronpeterson/9637291 to your computer and use it in GitHub Desktop.
get_adjacent_post buster for a wordpress custom post type.
<php
// in your constructor, etc
add_filter('get_previous_post_where', array($this, 'removePreviousPost'));
// have not tested this one but maybe?
add_filter('get_next_post_where', array($this, 'removePreviousPost'));
// kill with impossible sql
// @see https://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/link-template.php#L1173
public function removePreviousPost($where) {
global $post_type;
if( $post_type != self::$postType )
return $where;
return 'WHERE 1=2';
}
@ericleonardo
Copy link

Please, where do I put this code to disable get_adjacent_post?
(this function is slowing down my post load time, so I want to disable it)

I tried pasting that disable get_adjacent_post on my theme's function.php:
"syntax error, unexpected 'public' (T_PUBLIC), expecting end of file"

If I delete "public":
"Cannot use "self" when no class scope is active in"

Thanks!

@ericleonardo
Copy link

Already solved! I just put this into my theme's function.php:

// Removes the relational links for the posts adjacent to the current post
remove_action( 'wp_head', 'adjacent_posts_rel_link' );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );

Got it from here:
https://wordpress.stackexchange.com/questions/207104/edit-theme-wp-head

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment