Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: Create fake paged author pages when there are no posts

Discussion in 'Misc WordPress Requests' started by Beee, Dec 31, 2017.

  1. Beee

    Guest

    Reply To: Create fake paged author pages when there are no posts, by Beee

    WOOPTIE F***ING DOO !!! It works !!!

    As I suspected it was indeed the author name which was too ‘limited’ to include all in the query.

    This is the final result in pre-get-posts. It might look a bit different than you supplied it but tweaked/DRY-ed it a bit as well to eliminate other queries.

    function alter_query_for_author_mentioned_subpages( $query ) {
    if ( ! is_admin() && $query->is_main_query() && is_author() ) {

    $subpage = get_query_var( 'subpage' );
    $author_name = get_query_var( 'author_name' );

    if ( ( 'mentioned' === $subpage ) ) {
    $ppp = 18; // @TODO: get from setting
    $user_id = get_user_by( 'slug', $author_name )->ID;
    $mentioned_posts = idf_get_user_mentions( $user_id );

    $query->set( 'posts_per_page', $ppp );

    if ( $mentioned_posts ) {

    $authors = get_all_authors_ids();
    $authors[] = $user_id;

    $query->set( 'post__in', $mentioned_posts );

    // Reset author name
    $query->set( 'author_name', '' );

    // Store author name in fake_author_name query var
    $query->set( 'fake_author_name', $author_name );

    }

    add_filter( 'the_posts', 'idf_undo_reset_author_name', 99, 2 );
    }
    }
    }
    add_action( 'pre_get_posts', 'alter_query_for_author_mentioned_subpages' );

    Thanks @keesiemeijer couldn’t have fixed it without you I think.

    Reply To: Create fake paged author pages when there are no posts
     
    #1

Share This Page

Monarch Social Sharing Plugin