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

Display a Specific Link if User Has Post Published
Easy
Web Hosting Canada

Last modified : Oct 01 2022

Estimated reading time : 0 minutes, 42 seconds - 80 words

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);
}

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>