How can I limit the length of the previous/next posts in my WordPress Theme?

Here’s a little coding that should implement this for you: <?php $max_length = 5; // set max character length here $next = get_next_post()->ID; $prev = get_previous_post()->ID; if( $prev ) { $title = get_the_title( $prev ); $link = get_the_permalink( $prev ); $post_name = mb_strlen( $title ) > $max_length ? mb_substr( $title, 0, $max_length ) . ‘ … Read more

next and previous post link ordered alphabetically

Find the solution: The hole snippet looks like this: <?php function filter_next_post_sort($sort) { global $post; if (get_post_type($post) == ‘MyCustomPostType’) { $sort = “ORDER BY p.post_title ASC LIMIT 1”; } else{ $sort = “ORDER BY p.post_date ASC LIMIT 1”; } return $sort; } function filter_next_post_where($where) { global $post, $wpdb; if (get_post_type($post) == ‘MyCustomPostType’) { return $wpdb->prepare(“WHERE … Read more

How can I get next/ previous post links to order by a filter (by the last word of the title)?

Reviewing the MySQL string functions, it looks like you could use the SUBSTRING_INDEX() function: ORDER BY SUBSTRING_INDEX( p.post_title, ‘ ‘, -1 ) {ASC|DESC} LIMIT 1 to order by the last word of the post title. You could test this method within your orderby filters. Example: Prev/Next CPT – ordered by last word in post title … Read more

get_adjacent_post alternative on a very large db

I don’t see a way to make the query faster, but we can cache the result. Unfortunately, there is no hook to circumvent next_post_link() and previous_post_link(), so we have to replace those functions with custom functions. The following sample code uses a post meta field to store the result. There might be side effects – … Read more

How to get next and previous post links, alphabetically by title, across post types, in a shortcode

So in order to do this, I had to filter the SQL queries. I found this snippet that filters post order by title and returns them for next and previous post links. Unfortunately, this doesn’t work in a custom post type. So I replaced ‘post’ with get_post_type($post) to grab the current post type and return … Read more

How can I add title attributes to next and previous post link functions?

Update As I deleted the Repo on GitHub, here’s a new answer. add_filter( ‘previous_post_link”https://wordpress.stackexchange.com/questions/13044/,”wpse13044_adjacent_post_link_tooltip’, 10, 2 ); add_filter( ‘next_post_link”https://wordpress.stackexchange.com/questions/13044/,”wpse13044_adjacent_post_link_tooltip’, 10, 2 ); function wpse13044_adjacent_post_link_tooltip( $format, $link ) { $previous=”previous_post_link” === current_filter(); // Get the next/previous post object $post = get_adjacent_post( false ,” ,$previous ); // Copypasta from cores `get_adjacent_post_link()` fn ” === $title = get_the_title( … Read more

Filter next_post_link() and previous_post_link() by meta_key?

I managed to get this working using nothing but WordPress filters, thanks to @Milo’s hint. Just note that these are pretty specific to my case but you shouldn’t have a problem modifying them for your own use. I am using Advanced Custom Fields with a Date Picker field called date and Prev/Next links only point … Read more