WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have gravity forms set up on my site and I am wanting to hide/show a form based on whether or not the user has posted an entry into the form/database. If they have made an entry, then I want to hide it and display some simple text.

I see that gravity forms allow you to limit number of entries but this is not quite what I am after.

I'm guessing I would have to query the database but I'm not really sure the best way to write it. Would I have to use something like get_posts and check if the author has an entry? Would this be the best way to do it?

share|improve this question

Try this;


    $user = wp_get_current_user();

    if ( count_user_posts( $user->ID ) >= 1 ) {

        // echo your text snippet

    } else {

        // echo your form



1) wp_get_current_user() returns the WP_User object which includes many properties for that user.

2) Since we only want the ID of the current user, we assign a variable of choice, in this instance $user which is equal to that of i.e. $user = wp_get_current_user().

3) Then we can grab the current user ID simply by declaring $user->ID

4) We pass $user->ID to our count_user_posts( $user->ID) function which is then measured against our condition being greater than or equal to 1 post.

5) Do your thing...


share|improve this answer

Try this

    global $wpdb;
    $user = wp_get_current_user();
    $sql = "SELECT id from " . $wpdb->prefix . "rg_lead WHERE created_by=" . $user->ID;
    $results = $wpdb->get_results($sql);
    if (count($results) > 0) {
        // An entry is made by the user for any form
         // Show form

If you know form id for example $form_id then use

$sql = "SELECT id from " . $wpdb->prefix . "rg_lead WHERE created_by=" . $user->ID . " AND form_id=" . $form_id;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.