• Resolved TheodorGr

    (@theodorgr)


    Hello and congrats on this marvellous plug in. Im not exactly a php expert, but I can work some things out so please bare with me.

    I am using a theme which features a “megamenu” (article previewsd displayed on menu hovering) and all sorts of goodies and is compatible with CPT as long as they are registered as normal “category” taxonomy. What I have done up to now, is disable the “event categories” and “event taxonomies” – in my theme’s functions.php file I have added the following:

    add_action('init', 'soft_add_default_boxes');
    function soft_add_default_boxes()
    {
    register_taxonomy_for_object_type('category', 'event');
    register_taxonomy_for_object_type('post_tag', 'event');
    }

    My event posts, are all correctly displayed as “normal” posts everywhere in the site – in latest posts widgets, and even in “normal” category page (not EM categories).
    Thus, I have created a normal category “events” and every CPT “event” I post, I assign it the category “events” and everything is good.
    I have also created the files
    category-events.php
    single-event.php
    so I can have a better overall control of what is displayed when I visit these posts.

    The problems:
    1.In the page website.com/category/events (thus, when category-events.php file is used) the events are displayed in the order they were publicized, not in the order of “upcoming events”. Ideally, I would like to order them from the most soon upcoming to the most far away in the future, and exclude the “past” events. I know I could use a custom page – template and the shortcode for events list the plug in provides but for the reasons I explained initially I need to stay in the normal category displaying of my theme.
    Is there a php code I can include in category-events.php to achieve what Im after?

    2. In the “megamenu” system of my theme, under the “events” category, the CPTs “event” are correctly displayed, BUT isntead of the modified “date of event” which is displayed on every single EM CPT post, I get the initial “publish date”. Is there a way to fix this too, provided have no problem editing core functionalities of my theme?

    I understand my issues are particularly connected to my implementation of EM as a “normal” post and perhaps are outside the scope of your support – any info, hints, or general guidance would be greatly appreciated.

    Thanks and sorry for the long post.

    https://ww.wp.xz.cn/plugins/events-manager/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    hi,

    1. here’s another article which may help you – http://wp-events-plugin.com/documentation/advanced-usage/

    2. it might require custom coding on your theme or using additional hooks or filters.

    Thread Starter TheodorGr

    (@theodorgr)

    Thank you for your reply – but I am not using the simple lists provided by the plug in due to the fact that I prefer the post styles of my theme.

    I managed to edit my theme’s category.php though to achieve excluding “past” events.

    I had in category.php

    $cb_qry = cb_get_qry();
    
    if ( $cb_qry->have_posts() ) :
        while ( $cb_qry->have_posts() ) : 
    
            $cb_qry->the_post();
            $cb_post_id = $post->ID;

    And added after that:

    if (in_category ('events')){
    			$postDate = strtotime(get_the_time("Y-m-d", $cb_post_id ));
                $todaysDate = strtotime("yesterday");
    if ( $postDate <= $todaysDate){
    	continue;
    }

    Which kills the “while” iteration when the post date (event date) is older than yesterday.

    But I really needed some guidance as to whether there is a better way to accomplish the same thing (less resource hungry, or generally more “approved” way of doing things).

    Similarly I dont mind editing my theme’s functions – php files, in orde to achieve what Im after for my second question.

    Thread Starter TheodorGr

    (@theodorgr)

    Found a solution for my second issue:

    I edited some of my themes functions and included this:

    if (in_category('events')) {
    				global $post;
    $EM_Event = em_get_event($post->ID, 'post_id');
    $EM_dates = $EM_Event->output('#_{j F Y}');
    
    // do stuff here....
    }

    Which helps me retrieve the “correct” start date of the event. So consider my second question as solved.

    I think the solution to the first issue is fine.

    Thread Starter TheodorGr

    (@theodorgr)

    Thanks for confirming…I actually dived into the functions of my theme, found the cb_get_qry() function and edited that instead – I believe this to be a more elegant solution, which by the way I found by searching a bit in these forums. Im posting here for others looking to do a similar thing:

    if ( 'event' == get_post_type() ) {
    $cb_featured_qry = array( 'post_type' => 'event', 'cat' => 'events',
    'post_status' => 'publish', 'meta_query' => array( 'key' => '_end_ts',
    'value' => (current_time('timestamp') - 14400), 'compare' => '>=',
    'type'=>'numeric' ), 'orderby' => 'meta_value_num', 'order' => 'ASC',
     'meta_key' => '_end_ts',
    'meta_value' => (current_time('timestamp')-14400), 'meta_value_num' =>
     (current_time('timestamp')-14400),'meta_compare' => '>=' ); }
    
    else     {
    	 // the custom query args my theme had
      }
    
    $cb_qry = new WP_Query( $cb_featured_qry );

    The above arguments, make the query return “event” posts ordered by their “end” timestamp ONLY if the end timestamp is 4 hours earlier than “now” thus in my frontend the “events” which have “ended” 4 hours ago, are not displayed.

    Thanks for the updated code, it might help someone else.

    Thread Starter TheodorGr

    (@theodorgr)

    Posting to mark this topic as “resolved”.

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

The topic ‘Displaying event posts as regular posts (advanced)’ is closed to new replies.