• Resolved nicolaelvin

    (@nicolaelvin)


    I have two different types of posts pages. I have a post page that always shows the posts of the site author and I have a posts page that shows the current logged in users posts. I want the next and prev links on each page to only get the next and prev posts of either site author or current logged in user, depending on what page we are on. I had a similar requirement with archives – i.e. only get those archives for current users, and someone kindly helped me out with that here. SO I figure it’s a similar sort of thing, I need to use filters?

Viewing 1 replies (of 1 total)
  • Thread Starter nicolaelvin

    (@nicolaelvin)

    I have solved with help from the answer to my other similar question.

    Add this where you want the prev and next post links to appear:

    global $archive_author_id;							$archive_author_id = get_current_user_id();
    
    add_filter('get_previous_post_where', 'get_prev_post_where_filter');							previous_post('%','previous post','no');
    							add_filter('get_next_post_where', 'get_next_post_where_filter');
    next_post('%','next post','no');

    And where in your functions.php file:

    function get_prev_post_where_filter($where) {
       global $archive_author_id;
       return $where .' AND post_author = ' . $archive_author_id;
    }
    
    function get_next_post_where_filter($where) {
       global $archive_author_id;
       return $where .' AND post_author = ' . $archive_author_id;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Get prev and next post of current logged in user?’ is closed to new replies.