Skip to:
Content
Pages
Categories
Search
Top
Bottom

Ajax load more posts on BuddyPress member profile


  • Henry
    Member

    @henrywright-1

    I am using Michael Martin’s approach to load the next page of posts in WordPress via AJAX:

    Load Next WordPress Posts With AJAX

    This approach works very well on my tag and category pages.

    My aim now is to display a list of posts on each BuddyPress member’s profile page and have the next page load via AJAX. The first part (displaying the list of posts) I can do like so:

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $args = array(
            'author' => bp_displayed_user_id(),
            'post_type' => 'post',
            'paged' => $paged
    );
    
    $query = new WP_Query( $args );

    The part I am struggling with is getting the next page of results to load via AJAX – as outlined in Michael Martin’s approach. Michael’s approach works fine on tag and category archives so why not on the BuddyPress member profile page?

Viewing 5 replies - 1 through 5 (of 5 total)

  • Henry
    Member

    @henrywright-1

    OK got it down to the built in WP function next_posts() not taking into account the current component and current action parts of the URL.

    The URL getting passed to the script is this username/page/3 whereas in BuddyPress we need username/current_component/current_action/page/3

    Now my next problem is how to modify the link returned by next_posts() to add in the additional bit of the URL?


    modemlooper
    Moderator

    @modemlooper

    why ajax? you will need a fall back if its disabled.


    Henry
    Member

    @henrywright-1

    A couple of reasons but mainly to keep everything on one page. A load more button for posts is also consistent with the activity feed load more approach.

    I was thinking the same about a fallback so I’ve added plain pagination to the page too – it gets hidden via the js so falls back nicely when js is disabled.


    modemlooper
    Moderator

    @modemlooper

    Why not just create a custom activity feed for only blog posts?


    Henry
    Member

    @henrywright-1

    I need the post list to stay updated e.g when a member updates a post, WP Query will display the updated title in the post list. With activity, the old entry will remain in the list and a new item will be written to the list as well.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Ajax load more posts on BuddyPress member profile’ is closed to new replies.
Skip to toolbar