Viewing 9 replies - 1 through 9 (of 9 total)
  • Hiya,

    If you want a list of events for use in PHP use the EM_Event::output() function

    Thanks,
    Phil

    Thread Starter cloc69

    (@cloc69)

    Hello philipjohn,

    in fact I’m modifying an existing theme, so I can’t make too much changes.

    I have some events on my first page (it’s not really a list…) -> see here

    The php code is working well, but I still need to filter

    – once if they are to come
    – then with a category

    And I have to adapt to the existing code cause I already spent hours to get things working, that’s why I would like to write something like

    if (....

    I’m not sure to be very clear, sorry if not.

    Plugin Author Marcus (aka @msykes)

    (@netweblogic)

    based on your OP, you should use something like:

    if ( $EM_Event->start > current_time('timestamp') ) {

    Thread Starter cloc69

    (@cloc69)

    Hello Marcus,

    thanks for your quick answer.

    I’ve tryed your code, but it doesn’t work :/ It returns nothing.

    Is there a specific attribute like is_future that I can use in this case?

    Plugin Support angelo_nwl

    (@angelo_nwl)

    is_future is equivalent to @marcus above code base on php file classes/em-event.php at around line 1279

    can I know how did you list events in php, is that using php loop?

    Thread Starter cloc69

    (@cloc69)

    Hello Angelo,

    you’re right, I’m using a php loop.
    In fact I’m not displaying a list. I use events attributes such as thumbnails, post title or link to create a portfolio gallery -> like this

    Here are the codes (please be kind, it’s a modified code from an existing one. I made lots of cleaning but I know it’s not 100% fine yet…)

    I first use a shortcode

    function pixGalleriesEvents( $atts, $content = null ) {
    
        global $wp_query,
        	$post,
        	$posts_per_page,
        	$layout,
        	$page_template,
        	$page_sidebar,
        	$pix_sort,
        	$pix_order,
        	$pix_sort_by_tag,
        	$pix_linkto,
        	$pagenavi,
        	$shortcode_found,
        	$excerpt_lines,
        	$no_sidebar,
        	$the_post_type,
    	$pix_titles,
    	$pix_comments,
    	$pix_more,
    	$pix_like,
    	$query_shortcode_found,
    	$args;
    
    	extract(shortcode_atts(array(
    		'layout' => '',
    		'excerpt' => '',
    		'sorting' => '',
    		'order' => '',
    		'sort' => '',
    		'amount' => '',
    		'linkto' => '',
    		'pagenavigation' => '',
    		'titles' => '',
    		'comments' => '',
    		'morelink' => '',
    		'likebutton' => '',
    		'featured'	=> 'true'
    	), $atts));
    
        $posts_per_page = $amount;
        $pix_linkto = $linkto;
        $excerpt_lines = $excerpt;
        $the_post_type = 'event';
        $pix_titles = $titles;
        $pix_comments = $comments;
        $pix_more = $morelink;
        $pix_like = $likebutton;
        $pagenavi = $pagenavigation=='' ? 'false' : $pagenavigation;
        $pix_sort = $sorting;
        $pix_order = $order;
        $pix_sort_by_tag = $sort;
        $shortcode = 'true';
    
        if ( $featured!="false" ) {
        	$pix_order = 'false';
        	$query_shortcode_found = true;
        	$args['post_type']='event';
        	$args['ignore_sticky_posts']=1;
        	$args['posts_per_page']=$posts_per_page;
    
       } else {
    		$query_shortcode_found = true;
    		$page_template = get_post_meta( $post->ID, '_wp_page_template', true );
    		$args['post_type']='event';
    		$args['ignore_sticky_posts']=1;
    		$args['posts_per_page']=$posts_per_page;
    		$args['orderby']=$_SESSION[$the_post_type.'_sort'];
    		$args['order']=$_SESSION[$the_post_type.'_order'];
    
       }
    
    	ob_start();
    
    	switch ( $layout ) {
    		case 'sixth':
    		case 'sixth_bis':
    		case 'seventh':
    		case 'seventh_bis':
    		case 'eighth':
    		case 'eighth_bis':
    			load_template( get_template_directory() . '/loop-first-events.php', false);
    			break;
    		case 'ninth':
    		case 'tenth':
    			load_template( get_template_directory() . '/loop-second.php', false);
    			$no_sidebar = true;
    			break;
    		default:
    			load_template( get_template_directory() . '/loop-third.php', false);
    	}
    
    	$args = '';
    
    	wp_reset_postdata();
    
    	return ob_get_clean();
    }
    add_shortcode("pix_galleries_events", "pixGalleriesEvents");

    Then I use the “loop-first-events.php” where I try to insert the conditional “if” instead of the second “if (class_exists(‘EM_Event’))” <- This one is working, that’s why I’m using it for testing…

    <?php
    	global $wp_query,
    	    $post,
    	    $layout,
    	    $pix_sort,
    	    $page_template,
    	    $page_sidebar,
    	    $posts_per_page,
    	    $the_post_type,
    	    $pagenavi,
    	    $shortcode_found,
    	    $pix_order,
    	    $pix_sort_by_tag,
    	    $pix_price,
    	    $pix_linkto,
    	    $pix_titles,
    	    $pix_comments,
    	    $pix_more,
    	    $pix_like,
    	    $args_shortcode_found,
    	    $query_shortcode_found,
    	    $wp_version,
    	    $mediaelement_en;
    
    	    $inner_shortcode_found = ( $args_shortcode_found==true || $query_shortcode_found==true ) ? true : false;
    
     						<?php if ( $shortcode_found ) {
    
    							$the_content = get_the_content();
    							$the_content = preg_replace('|\[pix_galleries_events(.*?)\]|','',$the_content);
    							echo html5autop(do_shortcode($the_content));
    
    						} ?>
    
    						<?php
    
    						if ( $args_shortcode_found ) {
    							global $args;
    						} elseif ( $query_shortcode_found ) {
    							global $args;
    						} else {
                                $args = $wp_query->query_vars;
    
                                $args['orderby'] = $_SESSION[$the_post_type.'_sort'];
                                if ($args['orderby'] == 'price') {
    								$args['meta_key'] = '_price';
    								$args['orderby'] = 'meta_value_num';
                                } elseif ($args['orderby'] == 'popularity') {
    								$args['meta_key'] = 'total_sales';
    								$args['orderby'] = 'meta_value_num';
                                } elseif ($args['orderby'] == 'rating') {
    								$args['meta_key'] = '';
    								$args['orderby'] = 'menu_order title';
    								$get_catalog_ordering_args = new WC_Query();
    								add_filter( 'posts_clauses', array( $get_catalog_ordering_args, 'order_by_rating_post_clauses' ) );
                                }
                                $args['order'] = $_SESSION[$the_post_type.'_order'];
                                $args['posts_per_page'] = $posts_per_page;
                                $args['post__in'] = $post__in;
                                //$args['post_type'] = $the_post_type;
                            }
                            $args['paged'] = $paged;
    
    						$my_query = new wp_query( $args );
    
    						if ( $my_query->have_posts() ) : ?>
    
    							<?php
    								if (class_exists('EM_Event')) {
    							?>
    
                               <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>   
    
    							   <div class="entry post-id-<?php echo get_the_id(); ?> alignleft" data-sort="<?php echo $dataSort; ?>">
    
    									<?php 
    
    									$sc_date = $myquery->thepost->start;
    
    									if (class_exists('EM_Event')){
    
    	                                    $imageTh = get_the_post_thumbnail($image, $thumb_size );
    										echo '<div class="pix_column pix_column_thumb '.$column_size.' alignleft">';
    										if ( $pix_linkto == 'colorbox' ) {
    											echo '<a href="'.$image.'" data-rel="pix_slideshow">';
    										} elseif ( $pix_linkto == 'page' ) {
    											echo '<a href="'.get_permalink().'">';
    										}
    										echo $imageTh;
    
    										if ( $pix_linkto == 'colorbox' || $pix_linkto == 'page' ) {
    											echo '</a>';
    										}
    										echo '<div class="entry-content">';
    										if ( ($pix_titles!='0' && $pix_titles!='false') ) {
    											echo '<h5><a href="'. get_permalink(). '" title="'. sprintf( esc_attr__( 'Go to %s', 'forte' ), the_title_attribute( 'echo=0' ) ) .'" rel="bookmark">'. get_the_title().' - '.$sc_date. '</a></h5>';
    										}
    
    										if ( (function_exists('printGetLikes')  && $pix_like=='true') || $pix_more=='true' || ($pix_comments == 'true' && comments_open()) ) {
    				                            echo '<div class="entry-meta">';
    
    				                                        if ($pix_comments == 'true' && comments_open()) {
    				                                            if( get_comments_number() != '0' ) {
    				                                                echo '<span class="pix_meta_comments"><a href="'.get_permalink($post->ID).'#comments"><i class="icon-comment"></i> '.get_comments_number().'</a></span>'.PHP_EOL;
    				                                            }
    				                                        }
    				                                        if ( function_exists('printGetLikes') && $pix_like=='true' ) {
    				                                            echo '<span class="like-this">'.
    				                                                printGetLikes(get_the_ID()).
    				                                            '</span>'.PHP_EOL;
    				                                        }
    				                                    ?>
    													<?php
    
    				                                echo '</div>';
    				                            }
    			                            echo '</div>
    			                            </div>';
    									 }
    									?>
    
                                    </div><!-- .entry -->
    
                                    <span class="maybe_clear alignleft"></span>
    
                                <?php endwhile; wp_reset_postdata(); ?>
    
    	                        <?php } /*subcategories*/ ?>    
    
    	            			</div><!-- .simple_grid -->
    
                            <?php else : ?>
    
        						<?php echo '<div class="clear"></div>'.html5autop(do_shortcode(pix_get_option('pix_search_content'))); ?>
    
                            <?php endif; ?>
    
    <?php if ( !$inner_shortcode_found ) { ?>
    
    	                    </div><!-- .pix_column_990 -->
                        </div><!-- .pix_column -->                  
    
    				</div><!-- .pix_column_990 -->
    
    <?php } ?>
    		</div>
    
    <?php
    	$pix_sort = false;
    	$pix_order = false;
    	$pix_sort_by_tag = false;
    	$pix_price = false;
        $args_shortcode_found = false;
        $query_shortcode_found = false;
    ?>
    Plugin Support angelo_nwl

    (@angelo_nwl)

    Here’s a sample snippet of how to run a wp_query, but you’ll need to tweak it as needed:

    unction my_em_wp_query(){
    	$args = array(
    		'post_type' => 'event',
    		'posts_per_page' => 100,
    		'meta_query' => array( 'key' => '_start_ts', 'value' => current_time('timestamp'), 'compare' => '>=', 'type'=>'numeric' ),
    		'orderby' => 'meta_value_num',
    		'order' => 'ASC',
    		'meta_key' => '_start_ts',
    		'meta_value' => current_time('timestamp'),
    		'meta_value_num' => current_time('timestamp'),
    		'meta_compare' => '>='
    	);
    
    	// The Query
    	$query = new WP_Query( $args );
    
    	// The Loop
    	while($query->have_posts()):
    	$query->next_post();
    	$id = $query->post->ID;
    	echo '<li>';
    	echo get_the_title($id);
    	echo ' - '. get_post_meta($id, '_event_start_date', true);
    	echo '</li>';
    	endwhile;
    
    	// Reset Post Data
    	wp_reset_postdata();
    }
    add_shortcode('em_wp_query','my_em_wp_query');
    Thread Starter cloc69

    (@cloc69)

    Excellent,

    thanks Angelo

    I used your sample to find the code to extract the date:

    $sc_date = get_post_meta($id, '_event_start_date', true);
    if ( $sc_date > date("Y-m-d") )

    The “current_time(‘timestamp’)” does not work, as it has not the same date format.

    Just a last question; If I want to extract the category, what the syntax should be?
    Is the following correct?

    get_post_meta($id, '_event_category', true);

    Hiya,

    Actually, you can use wp_get_post_terms()

    Cheers,
    Phil

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Filtering events to come with PHP’ is closed to new replies.