I just stumbled over an issue while programming my own WordPress theme and I need your help.
I defined an author.php
file which should display the static pages and the blog pages of a given author. You have to know, that our website has a lot of pages with sub-, subsub- and even subsubsub- pages. All these pages were publishes by the "webmaster"-Account. Inside these pages, our content pages are situated. These child pages are published by our different authors and should be displayed on the author-page.
Example:
Practical courses (Webmaster)
Chemistry (Webmaster)
Qualitative analysis (Webmaster)
Proofs for anions (Webmaster)
Sulfide (Author)
Carbonate (Author)
... (Author)
Proofs for cations (Webmaster)
- ...
Physical chemistry (Webmaster)
- ...
Physics (Webmaster)
- Light diffraction (Webmaster)
In this example the "Sulfide" page would be the actual content. And that page should be visible on the author page of the author that published id.
I now added this code to display the pages of a specific author:
$author_id = $_GET['author'];
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'authors' => $author_id,
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages( $args );
foreach ( $pages as $page ) { ?>
<div class="col-md-4 article-item" style="cursor: pointer;" onclick="location.href='<?php echo get_page_link( $page->ID ); ?>'">
<h4><?php echo $page->post_title; ?></h4>
<?php if ( has_post_thumbnail($page->ID) ) {
echo get_the_post_thumbnail( $page->ID, 'post-thumbnail', array( 'class' => 'col-img' ) );
}
else {
echo '<img src="https://placehold.it/200x200?text=Icon" class="col-img wp-post-image round" />';
}
?>
<p class="excerpt"><?php echo $page->post_excerpt; ?></p>
</div>
<?php } ?>
Unfortunately every page is returned for every author and not only the pages published by that specific author.
If I hardcode the ID to a specific value - of an author that has published some content pages on our side - ($author_id = 2;
) nothing is returned. But if hardcoding the ID of the webmaster all the posts of the webmaster are shown (without the content posts which were published by an author)! So it seems to rely on the fact, that the content pages are subpages. For me, WordPress first checks if the parent pages are published by the given ID. If there are some, it checks if there are subpages of these parent pages which are published by that same ID.
In my case, it checks if the author of the ID "2" has published a parent page and gets a boolean of "false" and so does not even check to find subpages...
Do you know how I could edit the query so that the child pages are returned even if the parent page was published by an other author?
Thanks in advance!
'authors'
parameter takes a string. codex.wordpress.org/Function_Reference/get_pagesstrval($author_id)
now, but unfortunately it only "reversed" the problem. Now the authors page shows every page, even those that were not published by that author But I think that I see what Wordpress does here: It seems, that every page is output which contains a page posted by that author. Ironically this is the exact opposite of the previous behavior...