WordPress.org

Forums

Events Manager
[resolved] Show events as regular posts (articles) (41 posts)

  1. hixen
    Member
    Posted 2 years ago #

    Marcus:

    EM does one thing when a post is loaded into the loop, which is it changes the default published date to the start date of the event (does not change it in the actual $post object though).

    Is it possible to do this with a custom query? or do I have to use the following code?

    if (class_exists('EM_Events')) {
    	echo EM_Events::output(array(
    		'limit' => 10,
    		'format' => '<h4>#_EVENTLINK</h4>',
    	));
    }
  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    do you mwan WP_Query?

    If so, then yes, you just need to make sure post_type = event or the constant EM_POST_TYPE_EVENT

  3. hixen
    Member
    Posted 2 years ago #

    This is the code i'm trying out, but it posts my events after published date, instead of start date.

    What is the EM_POST_TYPE_EVENT, and how do I use that? is there any documentation, examples?

    <?php
    	$loop = new WP_Query( array(
    	'post_type' => 'event',
            'posts_per_page' => 5,
    )); ?>
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    <?php // added this to be able to use shortcodes and placeholders
    	$EM_Event = em_get_event($post->ID, 'post_id'); ?>
    
    	<h4><?php echo $EM_Event->output('#_EVENTLINK'); ?></h4>
    
    <?php endwhile; /* End loop */ ?>
    <?php wp_reset_query(); ?>
  4. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    not atm, working on it

    I mean like this:

    $loop = new WP_Query( array(
    	'post_type' => EM_POST_TYPE_EVENT,
            'posts_per_page' => 5,
    ));

    your way should work fine though, maybe you need to add this at the top

    global $post;

  5. hixen
    Member
    Posted 2 years ago #

    Marcus: I was never able to use WP_Query like you described, but found another solution, and now it also sorts my events posts with start date instead of publish date.

    <?php
    	global $query_string;
    	query_posts( $query_string . '&post_type=event&posts_per_page=5' );
    ?>
  6. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    interesting, i wouldn't think there'd be a difference there....

  7. af3
    Member
    Posted 2 years ago #

    Hi all, thanks for this snippet. I am trying to do the same but to only show events in the frontpage that are occuring TODAY's date. How can I do that?

    thx

  8. sloop88
    Member
    Posted 2 years ago #

    I added aglonwl's snipped into my functions.php

    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts( $query ) {
    	if ( is_home() && false == $query->query_vars['suppress_filters'] )
    		$query->set( 'post_type', array( 'post', 'event' ) );
    	return $query;
    }

    and the posts are now being displayed on the front page. However, the entire post is being displayed instead of a summary (as I've set in wp settings), and adding more tags does not help. How can I fix this?

  9. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    chances are you need to disable 'override with formats' in Events > Settings > Pages > Events List/Archives

    downside is this'd apply to the events page too, you could get round this by leaving that option on and adding this sort of thing:

    add_action('template_redirect','my_homepage_em_change');
    function my_homepage_em_change(){
    	if(is_home()){
    		add_filter('option_dbem_cp_events_formats',function(){return false;});
    	}
    }
    }

    disclaimer: not tested

  10. sloop88
    Member
    Posted 2 years ago #

    Hey Marcus, thanks for the quick response mate!

    I followed your advice, and disabled override with formats in Events List/Archives but that didn't affect the front page.
    When I disabled formatting for Event Pages, this then caused the event posts on the front page to behave like regular ones (with the "more" tags working, which is all I really want), but of course without the map and other goodies from the formatting.

    Unfortunately, I couldn't the code you gave code working, but from what I understand of it, it will disable formatting on posts only when they are on the home page, which will remove the maps and stuff once again, but I can live it that if it works.

  11. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    I think there's an extra } in that code snippet. I played around with this and it worked for me:

    //prevents formatting on the homepage if the events in homepage mod is used
    function my_em_homepage_eventformats(){
    	if(is_home()){
    		add_filter('option_dbem_cp_events_formats',function(){return false;});
    	}
    }
    add_action('template_redirect','my_em_homepage_eventformats');

    problem now is that events with bookings still show the booking form, would require some more digging.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Events Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic