Title: PHP Count current events?
Last modified: April 11, 2018

---

# PHP Count current events?

 *  Resolved [jockebq](https://wordpress.org/support/users/jockebq/)
 * (@jockebq)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/php-count-current-events/)
 * Hi,
 * This is a very advanced question, but I am trying to make a function which changes
   the CSS ID if true. And what I want it to do is to count the current events (
   the posts).
    This is the function I have come up with:
 *     ```
         if (count($vsel_current_query) > 20) {
             $div_id = 'test2';
         }
         else {
             $div_id = 'test';
         }
       ```
   
 * The reason I try with $vsel_current_query is because of this one:
    `$output .
   = get_next_posts_link( __( 'Next &raquo;', 'events' ), $vsel_current_query->max_num_pages);`
   Which I think is counting the current event posts, and if they are more than 
   the Max Blog posts setting in WordPress it will display the Next button.
 * Can you help me figure this one out?
 * Thank you!

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

 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/php-count-current-events/#post-10170329)
 * Hi,
 * Cannot promise you that I have a proper solution, but which ID do you want to
   change? The ID of certain events? The ID of an element of your page? Another 
   ID?
 * Guido
 *  Thread Starter [jockebq](https://wordpress.org/support/users/jockebq/)
 * (@jockebq)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/php-count-current-events/#post-10170671)
 * Don’t remember the name right now but I dont think the ID is what matters, but
   I cannot figure out how to get the number of posts/events on the current day.
   Do you know which php function to call?
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/php-count-current-events/#post-10170780)
 * Hi,
 * There’s no function inside my plugin for that, you should write your own function,
   have found [this example](https://wordpress.stackexchange.com/questions/106383/count-posts-or-custom-post-types-from-last-24-hours-or-from-today).
 * Guido
 *  Thread Starter [jockebq](https://wordpress.org/support/users/jockebq/)
 * (@jockebq)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/php-count-current-events/#post-10170837)
 * Aha! Great find, i read through it, but VSEL works differently right? That function
   applies to the last 24 hours. And your current events will be current date, not
   last 24 hours, How would you do this for the current day instead?
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/php-count-current-events/#post-10171582)
 * Hi,
 * Ok, you can retrieve the number of current (today’s) posts by using the current
   events shortcode query. I’ve created this function:
 *     ```
       function vsel_current_events_count() {
       	$today = strtotime( 'today' );
       	$vsel_meta_query = array( 
       		'relation' => 'OR',
       		array( 
       			'key' => 'event-date', 
       			'value' => $today, 
       			'compare' => '==', 
       			'type' => 'NUMERIC'
       		), 
       		array( 
       			'relation' => 'AND', 
       			array( 
       				'key' => 'event-start-date', 
       				'value' => $today, 
       				'compare' => '<=', 
       				'type' => 'NUMERIC'
       			), 
       			array( 
       				'key' => 'event-date', 
       				'value' => $today, 
       				'compare' => '>',
       				'type' => 'NUMERIC'
       			) 
       		) 
       	); 
       	$vsel_query_args = array( 
       		'post_type' => 'event', 
       		'post_status' => 'publish', 
       		'meta_key' => 'event-start-date', 
       		'orderby' => 'meta_value_num', 
       		'meta_query' => $vsel_meta_query
       	); 
       	$vsel_current_query = new WP_Query( $vsel_query_args );
   
       	return $vsel_current_query->post_count;
       }
       ```
   
 * Now you can use this number elsewhere by calling the function:
 *     ```
       vsel_current_events_count()
       ```
   
 * Guido
 *  Thread Starter [jockebq](https://wordpress.org/support/users/jockebq/)
 * (@jockebq)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/php-count-current-events/#post-10175435)
 * Wow!! That was very nice of you! It works perfectly! Thank you!
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/php-count-current-events/#post-10175652)
 * Great 🙂
 * If you somehow get a conflict with the original current events query, please 
   change the query name `vsel_current_query` in this function into something else
   such as `vsel_custom_query`.
 * Will mark this thread resolved.
 * Guido

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

The topic ‘PHP Count current events?’ is closed to new replies.

 * ![](https://ps.w.org/very-simple-event-list/assets/icon-256x256.png?rev=1415754)
 * [VS Event List](https://wordpress.org/plugins/very-simple-event-list/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/very-simple-event-list/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/very-simple-event-list/)
 * [Active Topics](https://wordpress.org/support/plugin/very-simple-event-list/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/very-simple-event-list/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/very-simple-event-list/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Guido](https://wordpress.org/support/users/guido07111975/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/php-count-current-events/#post-10175652)
 * Status: resolved