WordPress.org

Ready to get started?Download WordPress

Forums

All-in-One Event Calendar
[resolved] Pagination breaks when ai1ec_event posts are included in query. (4 posts)

  1. thatstevensguy
    Member
    Posted 1 year ago #

    Basically I am trying to load both recent blog posts and ai1ec_event posts into one blog (news and events) page. It appears to show them all when I use wp_query and grab the event posts along with the regular posts.

    If I disable pagination (increase limit) they all display fine, but as soon as I enable pagination I get 404 Not Found when I try to access page 3, sometimes I can get page 2 to work. You would think if pagination was not working it would 404 on page 2 every time so I am completely confused.

    I have tried all the solutions for custom posts types available on the internet, and have found one other person with the identical bug I have and ai1ec. I am hoping someone can offer a solution or explain why this is happening.

    Here is the query I am trying.

    $wp_query =  new WP_Query(array('post_type' => array('post', 'ai1ec_event'), 'paged' => $paged));
    
    // Proceed with the loop.

    http://wordpress.org/extend/plugins/all-in-one-event-calendar/

  2. thatstevensguy
    Member
    Posted 1 year ago #

    Ok after googling for a few days it seems to be a WordPress 3.4 bug.

    Add this code to your functions.php if you are experiencing this bug and trying to do what I am, that is, include events with posts in one latest 'news and events' page.

    What triggered me to believe it isn't the plugin, was when pagination worked fine in search results.

    // Fixes pagination bug with WP 3.4 and the homepage when using custom post types (latest posts).
    function custom_query_for_homepage( $query ) {
    	if( $query->is_main_query() && $query->is_home() ) {
    		$query->set( 'post_type', array( 'post', 'ai1ec_event' ) );
    	}
    }
    add_action( 'pre_get_posts', 'custom_query_for_homepage' );
  3. wilsonilo
    Member
    Posted 1 year ago #

    My friend i just want to tank you soo much, saved my ass!
    Just added this to functions.php and my custom post_types worked out.
    Again thanks!

  4. Richard
    Member
    Posted 1 year ago #

    @thatstevensguy: thank you for sharing this. I am sure this will benefit several of our users.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic