How to exclude or filter password protected posts when using next_post_link() previous_post_link

The function next_post_link() allow excludes, with the parameter excluded_terms. Add a list of the IDs of the password protected posts to this param. You get a list of all password protected posts with the follow example via DB select. $password_pages = $wpdb->get_col(“SELECT ID FROM $wpdb->posts WHERE post_status=”publish” AND post_type=”post” AND post_password !=””); Alternative can you … Read more

Displaying the author of next and previous posts in pagination?

Yes, you can do that. Change <?php previous_post_link(); ?> and <?php next_post_link(); ?> with the following code: For previous post: <?php $prev_post = get_previous_post(); $prev_user = get_user_by( ‘id’, $prev_post->post_author ); if (!empty( $prev_post )): ?> <a href=”https://wordpress.stackexchange.com/questions/248618/<?php echo $prev_post->guid ?>”><?php echo $prev_post->post_title ?> (<?php echo $prev_user->first_name . ‘ ‘ . $prev_user->last_name; ?>)</a> <?php endif ?> … Read more

next_post_link / previous_post_link not working with WP_Query

next_post_link & previous_post_link work off the global $wp_query. You could simply overwrite the main query with $wp_query =& $query, or replace your custom query with the standard ‘global’ functions. <?php query_posts( array( “post_type” => “page”, “page_id” => $post->ID ) ) ?> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post() … Read more

Modify previous and next post links to current Authors Other posts

The correct method of doing this since WordPress 4.4 is simply the following: add_filter( “get_next_post_where”, function($where, $in_same_term, $excluded_terms, $taxonomy, $post){ $where .= ” AND p.post_author=””.$post->post_author.”””; return $where; }, 10, 5); add_filter( “get_previous_post_where”, function($where, $in_same_term, $excluded_terms, $taxonomy, $post){ $where .= ” AND p.post_author=””.$post->post_author.”””; return $where; }, 10, 5); Note: Please do not follow levidia1221’s accepted response, … Read more

WordPress next/prev links Issue

From the Codex (emphasis mine): In standard usage (within the default, unaltered loop) next_post_link will generate a link to a post that is newer (more recent) than the current post. This is in contrary to the similarly-named previous_posts_link, which will typically link to a page of posts that is older than the current batch. It … Read more

previous_posts_link and next_posts_link, how to return the next/previous post’s title as the url

The functions you are using refer to the next or prev paginated set of posts, not a single post, hence the format they are in. Try using get_adjacent_post() instead. <?php $prev = get_adjacent_post(false, ”, true) $next = get_adjacent_post(false, ”, false) //use an if to check if anything was returned and if it has, display a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)