-
richib
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. -
Fernando
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
-
richib
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 !
- You must be logged in to reply to this topic.