Viewing 15 replies - 1 through 15 (of 15 total)
  • Never used the plugin but in:
    http://plugins.svn.wordpress.org/event-organiser/tags/1.4.2/includes/event-organiser-event-functions.php

    there’s this:

    $defaults = array(
    		'numberposts'=>-1,
    		'orderby'=> 'eventstart',
    		'order'=> 'ASC',
    		'showrepeats'=>1,
    		'group_events_by'=>'',
    		'showpastevents'=>$eo_settings_array['showpast']);

    So it would appear in your shortcode, you can use order=”DESC”

    Thread Starter Ian Anderson Gray

    (@baritoneuk)

    Thanks, however I’m not using a shortcode- I am using the event Archive template file which uses a WordPress loop. I’m still a bit of a WordPress noob so I can’t work out how to change the order. Is it supposed to be ordered by date Ascending? I’d have thought it was more helpful to order the archive in date descending. Is there a way I can modify the template to achieve this?

    http://plugins.svn.wordpress.org/event-organiser/tags/1.4.2/templates/archive-event.php

    Read the notice in that file. Save a copy of this in your theme’s directory.

    Then in that file find this:

    <div id="content" role="main">
    <?php if ( have_posts() ) : ?>

    Make it this:

    <div id="content" role="main">
    <?php global $query_string; query_posts($query_string . "&order=ASC"); ?>
    <?php if ( have_posts() ) : ?>

    see if that works.

    There is reason behind this madness!

    By default, events are displayed in chronological order, with earlier events first – which is normally how events would be displayed when showing ‘up coming events’. (‘Archive’ in this sense doesn’t necessarily mean an archive – but rather a list of the events…).

    Please do not use query_posts (see this post).

    The order be reversed by hooking onto pre_get_posts hook (with priority 5 so it occurs before EO intercepts it).

    add_action('pre_get_posts','wpse50761_alter_query',5);
    function wpse50761_alter_query($query){
    
          if( $query->is_main_query() && is_post_type_archive('event') ){
              $query->set('order','DESC');
          }
    }
    Thread Starter Ian Anderson Gray

    (@baritoneuk)

    Thanks, Stephen. Sorry for being really thick (still a bit of a noob!). I’m assuming I put this in my functions.php file? If not, where do I put it? I only want it to alter the order for the events archive template. I tried adding it to my functions.php file without success.

    Yup functions.php and it should work.

    The is_post_type_archive('event') makes sure it only effects the event archive.

    Thread Starter Ian Anderson Gray

    (@baritoneuk)

    Unfortunately it isn’t working for me. Is there anything I can give you to troubleshoot? All I can say it isn’t working despite putting the above code in my functions.php file.

    Try

    add_action('pre_get_posts','wpse50761_alter_query',5);
    function wpse50761_alter_query($query){
    
          if( $query->is_main_query() && is_post_type_archive('event') ){
              $query->set('order','DESC');
              var_dump($query);
          }
    }

    That will print the $query object at the top of the page. If it isn’t printed, then the main query isn’t for the event archive (unlikely). If it is set, and the ‘order’ is DESC – then its working, but another plug-in is over-riding it (try disabling all other plug-ins).

    Thread Starter Ian Anderson Gray

    (@baritoneuk)

    Sorry for delay. I’ve tried disabling all plugins except for EO but with no success. The order in the query string is DESC but obviously something is going wrong.

    Sorry baritoneuk that is has taken so long – a minor bug in the plug-in, you need to specify an ‘orderby’ too:

    add_action('pre_get_posts','wpse50761_alter_query',15);
    function wpse50761_alter_query($query){
          if( $query->is_main_query() && is_post_type_archive('event') ){
    	$query->set('orderby','eventstart');
    	$query->set('order','desc');
          }
    }
    Thread Starter Ian Anderson Gray

    (@baritoneuk)

    Thanks, Stephen.

    I’m a little confused here, as it seems to work now even though I didn’t alter the code. Has this been fixed in the latest version of EO? If not, maybe I altered the code and forgot about it! I really must remember to comment the code.

    Nope… default order is ‘ASC’ still… and you would still need to specify the orderby parameter.

    hey there,
    thanks, was looking for this. one little thing, why the funny name for wpse50761_alter_query? any particular reason on that?

    just realized something, i actually use the event-category template to list all events, but still get them listed with oldest first. tried to adjust the snippet to that, but still ain’t working. any ideas?

    add_action('pre_get_posts','wpse50761_alter_query',15);
    function wpse50761_alter_query($query){
    if( $query->is_main_query() && is_category('events') ){
    $query->set('orderby','eventstart');
    $query->set('order','desc');
    }

    Plugin Author Stephen Harris

    (@stephenharris)

    Hi Hollawaldfee

    The prefix ‘wpse506761’ is used because the code was taken from my answer here: http://wordpress.stackexchange.com/questions/50761/when-to-use-wp-query-query-posts-and-pre-get-posts/50762#50762 (note the ID of the question: *50761*.

    In general you should prefix functions names with something unique – and its just something of a habit now that I use wpse[Question ID] when answering questions on WPSE.

    As for your question, the is_category('term') function checks if the archive for the category ‘term’ is being displayed. But event categories are not a category term – they are an entirely different taxonomy.

    Try

    add_action('pre_get_posts','wpse50761_alter_query',15);
    function wpse50761_alter_query($query){
    if( $query->is_main_query() && is_tax( 'event-category' ) ){
        $query->set( 'orderby' , 'eventstart' );
        $query->set( 'order', 'desc' );
    }

    Sweet. Works. Thanks for the quick reply. I was about to echo all conditional tags in order to find out what’s unique 🙂

    As for the funct-name: I see the system.

    cheers again.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘[Plugin: Event Organiser] Archive Page: Change order to Descending’ is closed to new replies.