WordPress.org

Ready to get started?Download WordPress

Forums

Upcoming event posts (1 post)

  1. Gary
    Member
    Posted 1 year ago #

    Excuse my basic English!

    Last year, I have put together custom meta query script for upcoming event posts, arranged by event dates.

    The whole point of it is that I can use normal post for upcoming events and use the post to add images and/or attachements and so on.

    It allows flexibility as myself regularly get e-mails from various people with their event information.

    I have added custom fields for eventdate e.g. 2013-04-17.

    Here are the codes:

    Upcoming events starting from today:

    <?php
    
    $currentdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
    
    $wp_query = new WP_Query(  array (
    				'posts_per_page' => 10,
    				'orderby'=> 'menu_order',
    				'paged'=>$paged,
                    'post_type' => 'post',
                    'meta_query'=> array(
                        array(
                          'key' => 'eventdate',
                          'compare' => '>',
                          'value' => $currentdate,
                          'type' => 'DATE',
                        )),
                    'meta_key' => 'eventdate',
                    'orderby' => 'meta_value',
                    'order' => 'ASC'
        )
    );
    
    ?>

    Also for other catergory for all events including the previous month events too:

    <?php
    
    $currentdate = date("Y-m-d",mktime(0,0,0,date("m")-1,date("d"),date("Y")));
    
    $wp_query = new WP_Query(  array (
    				'posts_per_page' => 10,
    				'orderby'=> 'menu_order',
    				'paged'=>$paged,
                    'post_type' => 'post',
                    'meta_query'=> array(
                        array(
                          'key' => 'eventdate',
                          'compare' => '>',
                          'value' => $currentdate,
                          'type' => 'DATE',
                        )),
                    'meta_key' => 'eventdate',
                    'orderby' => 'meta_value',
                    'order' => 'ASC'
        )
    );
    
    ?>

    If the event listing gets longer than 10 posts, it would spill over into 2nd page and it was working fine last year until recently.

    However, paged is no longer working and I am not sure why but I think it was caused by a change of post query along with wordpress update?

    Is there a such plugin to replace this custom query so I will not have to insert custom query script like above?

    [No bumping thanks]

Topic Closed

This topic has been closed to new replies.

About this Topic