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

Prev/Next child navigation for current page?

All right, here it is, fully working: <?php $pagelist = get_pages(“child_of=”.$post->post_parent.”&parent=”.$post->post_parent.”&sort_column=menu_order&sort_order=asc”); $pages = array(); foreach ($pagelist as $page) { $pages[] += $page->ID; } $current = array_search($post->ID, $pages); $prevID = $pages[$current-1]; $nextID = $pages[$current+1]; ?> <div class=”navigation”> <?php if (!empty($prevID)) { ?> <div class=”previous”> <a href=”https://wordpress.stackexchange.com/questions/54422/<?php echo get_permalink($prevID); ?>” title=”<?php echo get_the_title($prevID); ?>”>Previous</a> </div> <?php } … Read more

Filter get_adjacent_post() for private posts, how to modify JOIN/WHERE?

First of all I suggest you to use a function to return the terms to exclude, that will help you to get them in different places without having to repeat code, e.g. in the ‘pre_get_posts’ filter and the adjacent post filters. So: function get_level_term_to_exclude() { if ( current_user_can (‘manage_options’) || current_user_can (‘view_level1_posts’) ) { return … 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

Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation

this is very simple to do… // next function next_shortcode($atts) { // global $post; -unnecessary return ‘<div class=”nav-next”>’.next_post_link( ‘%link’, ‘%title <span class=”meta-nav”>’ . _x( ”, ‘Next post link’, ‘ ‘ ) . ‘</span>’,true ).'</div>’; } add_shortcode( ‘next’, ‘next_shortcode’ ); //prev function prev_shortcode($atts) { //global $post; -unnecessary return ‘<div class=”nav-previous”>’.next_post_link( ‘%link’, ‘%title <span class=”meta-nav”>’ . _x( … Read more

How to Get Next or Previous Post in a Specific Tag?

get_adjacent_post(), which is used by all functions that return a (link to) the next or previous post, only has a $in_same_cat argument, which looks at the categories the post is in, not the tags. You could hook into the get_[next|previous]_post_join to modify the join query for your call, but then it’s probably easier to copy … 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