0

there are several authors on my site. I have a post type called jobs and I have a few articles where the author of the articles and post type jobs are the same, how can I show the articles of each author under their post type jobs page? Each author has his own page in Jobs. I am a newbie, if you can explain something like this to me, thank you this code get the currect author id but how show the posts under jobs?

$user_id = get_post_field( 'post_author', $post_id );

1 Answer 1

1

You can you this code to show posts based on user:

$args = array(
'author'        =>  $user_id,
'orderby'       =>  'post_date',
'order'         =>  'ASC',
'posts_per_page' => 1
);

$query = new WP_Query( $args );

if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();
    }
}
wp_reset_postdata();
2
  • thank's for reply; that's work but most add echo to show post while ( $query->have_posts() ) { $query->the_post(); echo '<li>' . get_the_title() . '</li>'; } Sep 19, 2022 at 13:10
  • You can use the_title() and the_content() for this and if user data stored in post_meta then you need to echo.
    – Prits
    Sep 20, 2022 at 12:09

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.