{"id":5132,"date":"2017-10-19T09:22:21","date_gmt":"2017-10-19T13:22:21","guid":{"rendered":"https:\/\/themespress.ca\/?p=5132"},"modified":"2022-10-01T14:45:24","modified_gmt":"2022-10-01T18:45:24","slug":"display-a-specific-link-if-user-has-post-published","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/display-a-specific-link-if-user-has-post-published\/","title":{"rendered":"Display a Specific Link if User Has Post Published"},"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 show you how to display a specific menu item if a user has a Post Type published.<\/p>\n<p>First we need to create a function that will allows us to create a query that will return the number of Post Type published by the user. In this example below, <strong>you need to replace the Post Type by yours<\/strong> or the posts. We need to return this query that the result is different than 0.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-8034544\" 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-8034544\" 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=\"\">function themespress_user_has_posts($user_id) {\n  $result = new WP_Query(array(\n    &#039;author&#039;           =&gt; $user_id,\n    &#039;post_type&#039;        =&gt; &#039;any&#039;,\n    &#039;post_status&#039;      =&gt; &#039;publish&#039;,\n    &#039;posts_per_page&#039;   =&gt; 1,\n  ));\n  return (count($result-&gt;posts)!=0);\n}<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial, we will show you how to display a specific menu item if a user has a Post Type published. First we need to create a function that<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/display-a-specific-link-if-user-has-post-published\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":5135,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[318],"class_list":["post-5132","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-functions"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/5132","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=5132"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/5132\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/5135"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=5132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=5132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=5132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}