NB: Make sure you do a back up of your theme, files and database before attempting the tutorials
Easy
Last modified : Oct 01 2022
Estimated reading time : 0 minutes, 42 seconds - 80 words
Share the post "Display a Specific Link if User Has Post Published"
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 will allows us to create a query that will return the number of Post Type published by the user. In this example below, you need to replace the Post Type by yours or the posts. We need to return this query that the result is different than 0.
function themespress_user_has_posts($user_id) { $result = new WP_Query(array( 'author' => $user_id, 'post_type' => 'any', 'post_status' => 'publish', 'posts_per_page' => 1, )); return (count($result->posts)!=0); }