Title: Use the count shortcode inside a PHP function
Last modified: February 13, 2017

---

# Use the count shortcode inside a PHP function

 *  Resolved [mackans](https://wordpress.org/support/users/mackans/)
 * (@mackans)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-the-count-shortcode-inside-a-php-function/)
 * Hi
    I have a form (CF7) and the submissions are stored in CFDB. Is it possible
   to use the count shortcode inside a PHP function and compare the output number
   against another number to decide whether or not to show the form? What I’m looking
   for is to **hide** the form when the number of submissions >600. This is the 
   function that I’ve tried:
 *     ```
       <?php
       $sumregistrations = <?php echo do_shortcode('[cfdb-count title="Registration"]'); ?>;
       if ($sumregistrations > 600 ): ?>
           //HIDE THE FORM
       <?php else : ?>
           //SHOW THE FORM
       <?php endif; ?>
       ```
   
 * I got some advice from a guy at stackoverflow and first and foremost he said 
   I can’t use a php function inside another php function. Secondly, he said:
 * > …this shortcode outputs a string wrapped in HTML. Therefore, you cannot use
   > it to compare against 600, as it will always return false. You should get the
   > count value directly from the db table.
 * Can you give some advice on how to achieve what I’m looking for? Or is it not
   possible at all?
 * Thanks

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Michael Simpson](https://wordpress.org/support/users/msimpson/)
 * (@msimpson)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-the-count-shortcode-inside-a-php-function/#post-8804685)
 * Similar to this example: [https://cfdbplugin.com/?page_id=367](https://cfdbplugin.com/?page_id=367)
 * Something like this might do it:
 *     ```
       require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
       $exp = new CFDBFormIterator();
       $exp->export('Registration', array('show' => 'submit_time', 'trans' => 'CountField(submit_time)'));
       $count = 0;
       while ($row = $exp->nextRow()) {
           $count = $row['submit_time'];
       }
       ```
   
    -  This reply was modified 9 years, 3 months ago by [Michael Simpson](https://wordpress.org/support/users/msimpson/).
 *  Thread Starter [mackans](https://wordpress.org/support/users/mackans/)
 * (@mackans)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-the-count-shortcode-inside-a-php-function/#post-8805524)
 * Thank you so much Michael! It works great! Here’s the final code that’s working,
   in case someone else need it:
 *     ```
       <?php require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
           $exp = new CFDBFormIterator();
           $exp->export('NAME OF THE FORM', array('show' => 'submit_time', 'trans' => 'CountField(submit_time)'));
           $count = 0;
           while ($row = $exp->nextRow()) {
               $count = $row['submit_time'];
           }
           if ($count > 600 ): ?>
               //Content to show if number of submissions are greater than 600.
           <?php else : ?>
               //Content to show if number of submissions are less than 600.
               //For example, show the form <?php echo do_shortcode('[contact-form-7 id="112" title="NAME OF THE FORM"]'); ?>
           <?php endif; ?>
       ```
   
 * Thank you again!
 * /Marcus
 *  Thread Starter [mackans](https://wordpress.org/support/users/mackans/)
 * (@mackans)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/use-the-count-shortcode-inside-a-php-function/#post-8880530)
 * Hi again
 * Your code above works great! I have another question now. How can I make the 
   function to exclude rows that has a value in a certain column?
 * For example, in the form I have a field that is optional to fill in. If the field
   is left blank I don’t want to include this submission (the row in the database)
   in the count function.
    -  This reply was modified 9 years, 2 months ago by [mackans](https://wordpress.org/support/users/mackans/).
 *  Plugin Author [Michael Simpson](https://wordpress.org/support/users/msimpson/)
 * (@msimpson)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/use-the-count-shortcode-inside-a-php-function/#post-8881611)
 * In the array you are passing to $exp->export, add
 * `"tfilter" => "yourfield==null"`
 * or whatever filter expression you prefer. “tfilter” expressions are evaluated
   prior to transform functions, “filter” expressions are evaluated after.
 *  Thread Starter [mackans](https://wordpress.org/support/users/mackans/)
 * (@mackans)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/use-the-count-shortcode-inside-a-php-function/#post-8886428)
 * Thank you! It works!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Use the count shortcode inside a PHP function’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/contact-form-7-to-database-extension_ffffff.
   svg)
 * [Contact Form DB](https://wordpress.org/plugins/contact-form-7-to-database-extension/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7-to-database-extension/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/reviews/)

## Tags

 * [count](https://wordpress.org/support/topic-tag/count/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 5 replies
 * 2 participants
 * Last reply from: [mackans](https://wordpress.org/support/users/mackans/)
 * Last activity: [9 years, 2 months ago](https://wordpress.org/support/topic/use-the-count-shortcode-inside-a-php-function/#post-8886428)
 * Status: resolved