WordPress.org

Ready to get started?Download WordPress

Forums

Event Organiser
[resolved] Different number of event posts per page than universal WP posts limit (13 posts)

  1. earthtojeremy
    Member
    Posted 2 years ago #

    Hi -

    I want to know if there's a way I can edit archive-event.php so that it shows a different number of event posts than the number set by the universal WP post limiter in the Settings area. I know there's a way to do it in the shortcode, but that doesn't help me here. I want to control it from the template. Is this possible?

    Thanks,
    Jeremy

    http://wordpress.org/extend/plugins/event-organiser/

  2. earthtojeremy
    Member
    Posted 2 years ago #

    And if this is any different or any easier, I really just want to remove the limit altogether, and show all upcoming events on one page. (Of course setting the limit to 9999 works fine too, whatever's easier.) Thanks.

  3. Stephen Harris
    Member
    Plugin Author

    Posted 2 years ago #

    Yup, this is really easy to do. You can use WordPress' pre_get_posts (see Codex) hook to alter the posts_per_page:

    function my_events_per_page( $query ) {
        if ( $query->is_main_query() && is_post_type_archive('event') ){
            //Display 50 posts for a custom post type called 'event'
            $query->query_vars['posts_per_page'] = 50;
            return;
        }
    }
    add_action('pre_get_posts', 'my_events_per_page', 1);

    To get all events set the posts_per_page variable to -1.

  4. earthtojeremy
    Member
    Posted 2 years ago #

    Thanks a lot. For anyone who isn't sure, the above code goes at the end of your theme's functions.php file.

    Thanks,
    Jeremy

  5. earthtojeremy
    Member
    Posted 2 years ago #

    Another question -- now that I've added the above code, the mini-list brought up by the [eo_events] shortcode lists every upcoming event. How can I limit it to the upcoming 5?

    Thanks,
    Jeremy

  6. earthtojeremy
    Member
    Posted 2 years ago #

    Also how do you remove the title attribute of the [eo_events] shortcode? I'm trying to get rid of the redundant title tooltip box that pops up when you hover over a event title link.

  7. earthtojeremy
    Member
    Posted 2 years ago #

    I figured out the post limiter problem -- just use the shortcode in the following manner:

    [eo_events posts_per_page="5"]

    This limits the events mini-widget to display the most recently upcoming 5.

  8. Stephen Harris
    Member
    Plugin Author

    Posted 2 years ago #

    Glad you got it sorted.

    Re. removing the title attribute. You can provide a custom 'template' (or place holder) to be used for each line in a list of events. See the documentation: http://www.harriswebsolutions.co.uk/event-organiser/documentation/shortcodes/event-list-shortcode/

  9. earthtojeremy
    Member
    Posted 2 years ago #

    I'm having the same limited posts issue on the venue pages. I want the venue pages to list all associated events on one page, no pagination. The code I added in functions.php doesn't affect this page. I've tried a few things but no luck so far, let me know what you think.

    Thanks,
    Jeremy

  10. Stephen Harris
    Member
    Plugin Author

    Posted 2 years ago #

    Yup, the conditional is_post_type_archive('event') checks if its the event post type archive page. The venue pages are the event-venue taxonomy archive pages;

    • is_post_type_archive('event') - is it the post type archive?
    • is_tax('event-venue') - is it a venue page
    • is_tax('event-category') - is it an event category page
    • is_tax('event-tag ') - is it an event tag page

    You can use the appropriate conditional in the pre_get_posts hook to set the number of events for each of those pages.

  11. earthtojeremy
    Member
    Posted 2 years ago #

    Thanks for your reply, but I can't figure out how to implement this. I tried adding another my_events_per_page hook with is_tax('event-venue') instead of is_post_type_archive('event'), but it returns the message that you can't declare the hook twice. I tried fitting is_tax('event-venue') into the original hook in addition to is_post_type_archive('event'), but I honestly have no clue what I'm doing.

    Here's the original hook:

    function my_events_per_page( $query ) {
        if ( $query->is_main_query() && is_post_type_archive('event') ){
            //Display 50 posts for a custom post type called 'event'
            $query->query_vars['posts_per_page'] = 999;
            return;
    
        }
    }
    add_action('pre_get_posts', 'my_events_per_page', 1);

    Can you show me where/how to insert is_tax('event-venue')?

    Thanks,
    Jeremy

  12. Stephen Harris
    Member
    Plugin Author

    Posted 2 years ago #

    You can specify them separately, or use the following (if you want to show all events, you can set the post_per_page=-1).

    function my_events_per_page( $query ) {
        if ( $query->is_main_query() && ( is_post_type_archive('event') || is_tax(event-venue) ) ){
            //Display all posts for post type event archive and event-venue taxonomy archive
            $query->query_vars['posts_per_page'] = -1;
            return;
    
        }
    }
    add_action('pre_get_posts', 'my_events_per_page', 1);
  13. earthtojeremy
    Member
    Posted 2 years ago #

    Works perfectly. Thanks again for all your help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic