0

On a website, I have 4 article authors. I want to display each author's posts on his own custom post page.

I have come up with this piece of code:

<ul class="author-posts">
  <?php $catquery = new WP_Query( 'cat=7&posts_per_page=30&order=DESC&author_name=john' );
    while($catquery->have_posts()) : $catquery->the_post();
   ?>
    <li class="author-post"><?php the_content();?></li>
<?php endwhile;?>

The problem with the code above is that only one author's name is john.

So the WP_Query does not display terry's posts.

If every parent page (actually, a custom post) has an author, how do I store the parent page's author in a variable so that I can show on it only the posts belonging to the current author?

Thank you!

1 Answer 1

0

I found it (easy one):

In functions.php:

// Allow author for custom post
function allowShowAuthor()
{
  add_post_type_support( 'cust_post-type', 'author' );
}

add_action('init','allowShowAuthor');

In the content template:

<ul class="author-posts">
 <?php
        $current_page_author = get_the_author();
        $catquery = new WP_Query( 'cat=7&posts_per_page=30&order=DESC&author_name=' . $current_page_author );
    while($catquery->have_posts()) : $catquery->the_post();
   ?>
    <li class="author-post"><?php the_content();?></li>
<?php endwhile;?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.