NB: Make sure you do a back up of your theme, files and database before attempting the tutorials


---- Last modified : 7 July 2021

With this tutorial, we will create a query which will display posts or post types of an author. This could be used in a scenario where a user wants to see their ads on an online classified advertising service.

First off, you must know that the author.php template could fill our need, however this is will be to create a more custom result.

First off, if not already done, you’ll need to create a template page in English.

Once the template is ready to go, you will be able to add your query to it and create your loop. For that, we will use the get_posts function to display our results.

In the example below, we have a news post type that displays this template which displays a user’s published news post.
Simply replace News by your post type. You will then be able to edit the arguments such as pagination, etc…

$args = array(
'posts_per_page' => 100,  // Limit to 5 posts
'post_type' => 'nouvelles',  // Query for the default Post type
'order_by' => 'post_date'  // Order by date posted
$last_five_posts = get_posts( $args );

foreach ( $last_five_posts as $post ) : setup_postdata( $post ); 
<?php /// Votre HTML / RÉSULTATS ICI ?>
<?php endforeach; wp_reset_postdata(); ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>