Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Author Page Post List

  • Hi,
    I’ve set up an author page where I am trying show all the posts and pages by the author, but I can only seem get the page to pull posts not pages.
    I have used an element to create this and set location to author archives, but cant seem to get it to pull pages by the author.
    Any help would be appreciated.
    Page added below.

  • Hi Richib,

    Can you try adding this PHP snippet?:

    function include_pages_in_author_archive($query) {
        if ($query->is_author && $query->is_main_query()) {
            $query->set('post_type', array('post', 'page'));
        }
    }
    
    add_action('pre_get_posts', 'include_pages_in_author_archive');

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

  • Hi,

    It seems to be working, how can I exclude certain pages like Disclaimer and Privacy policy etc?
    Basically, I just want pages to show that have an author box.

    Many thanks

  • Hi there,

    try this instead:

    
    function include_pages_in_author_archive($query) {
        // Check if it's the main query for an author archive
        if ($query->is_author && $query->is_main_query()) {
            
            // Exclude specific pages by ID
            $exclude_pages = array(1, 2, 3); // Replace with the actual page IDs you want to exclude
            $query->set('post_type', array('post', 'page'));
            $query->set('post__not_in', $exclude_pages);
        }
    }
    
    add_action('pre_get_posts', 'include_pages_in_author_archive');
    

    Update the $exclude_pages array with the IDs of the pages you want to exclude

  • Worked perfectly.

    Many thanks

  • Glad to hear that !

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.