{"id":4193,"date":"2020-04-11T14:44:38","date_gmt":"2020-04-11T18:44:38","guid":{"rendered":"https:\/\/themespress.ca\/?p=4193"},"modified":"2021-11-17T06:54:48","modified_gmt":"2021-11-17T11:54:48","slug":"display-an-authors-post-on-a-page-template","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/display-an-authors-post-on-a-page-template\/","title":{"rendered":"Display an Author&#8217;s Post on a Page Template"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>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.<\/p>\n<p>First off, you must know that the <a href=\"https:\/\/developer.wordpress.org\/themes\/basics\/template-hierarchy\/\" target=\"_blank\" rel=\"noopener noreferrer\">author.php<\/a> template could fill our need, however this is will be to create a more custom result.<\/p>\n<p>First off, if not already done, you&#8217;ll need to create a <a href=\"https:\/\/developer.wordpress.org\/themes\/template-files-section\/page-template-files\/\" target=\"_blank\" rel=\"noopener noreferrer\">template page in English<\/a>.<\/p>\n<p>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 <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/get_posts\/\" target=\"_blank\" rel=\"noopener noreferrer\">get_posts<\/a> function to display our results.<\/p>\n<p>In the example below, we have a news post type that displays this template which displays a user&#8217;s published news post. <br \/>\nSimply replace News by your post type. You will then be able to edit the arguments such as pagination, etc&#8230;<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-4435391\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-4435391\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php\n$args = array(\n&#039;posts_per_page&#039; =&gt; 100,  \/\/ Limit to 5 posts\n&#039;post_type&#039; =&gt; &#039;nouvelles&#039;,  \/\/ Query for the default Post type\n&#039;order_by&#039; =&gt; &#039;post_date&#039;  \/\/ Order by date posted\n);\n$last_five_posts = get_posts( $args );\n\nforeach ( $last_five_posts as $post ) : setup_postdata( $post ); \n?&gt;\n&lt;?php \/\/\/ Votre HTML \/ R&Eacute;SULTATS ICI ?&gt;\n&lt;?php endforeach; wp_reset_postdata(); ?&gt;<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"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<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/display-an-authors-post-on-a-page-template\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4926,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[322,326],"class_list":["post-4193","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-query","tag-users"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/4193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=4193"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/4193\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4926"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=4193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=4193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=4193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}