• Resolved davidsonh

    (@davidsonh)


    We have been using the Modern Tribe’s The Events Calendar WordPress plugin for 1-2+ years.

    I believe we’re having issues with the event widget we have set up in our header widget area (this is only an assumption and may very well be wrong).

    I’m receiving the following error message in the PHP error log (“***” indicates redacted information):
    ________________________________________________________________________________

    [07-Dec-2020 17:26:34 UTC] WordPress database error Not unique table/alias: ‘***_postmeta’ for query SELECT SQL_CALC_FOUND_ROWS DISTINCT ***_posts.*, CAST( orderby_event_date_meta.meta_value AS DATETIME ) AS event_date FROM ***_posts LEFT JOIN ***_postmeta ON (***_posts.ID = ***_postmeta.post_id AND ***_postmeta.meta_key = ‘_EventHideFromUpcoming’ ) LEFT JOIN ***_postmeta AS mt1 ON ( ***_posts.ID = mt1.post_id ) LEFT JOIN ***_postmeta ON ***_posts.ID = ***_postmeta.post_id

    LEFT JOIN ***_postmeta AS orderby_event_date_meta
    ON (
    orderby_event_date_meta.post_id = ***_posts.ID
    AND orderby_event_date_meta.meta_key = ‘_EventStartDate’
    )
    WHERE 1=1 AND (
    ***_postmeta.post_id IS NULL
    AND
    ( mt1.meta_key = ‘_EventEndDate’ AND CAST(mt1.meta_value AS DATETIME) > ‘2020-12-07 12:26:34’ )
    ) AND ***_posts.post_type = ‘tribe_events’ AND ((***_posts.post_status = ‘publish’)) GROUP BY ***_posts.ID ORDER BY event_date ASC, ***_posts.post_date ASC LIMIT 0, 1 made by require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(‘/themes/***/woocommerce/archive-product.php’), get_header, locate_template, load_template, require_once(‘/themes/***/header.php’), dynamic_sidebar, WP_Widget->display_callback, Tribe__Events__List_Widget->widget, Tribe__Events__List_Widget->widget_output, tribe_get_events, Tribe__Events__Query::getEvents, WP_Query->get_posts`

    • This topic was modified 5 years, 4 months ago by davidsonh.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Deblyn Prado

    (@deblynprado)

    Hi there @davidsonh !

    I’m sorry that you’re having issues with The Events Calendar.
    I’d like to ask you a few things to better understand the issue, ok?

    Do you know when this error started?
    If you remove the Widget, does this error disappear?

    Apparently you have some customizations in your theme. Would you mind to run our Testing for Conflicts tutorial to see if the issue it’s being caused by your Theme or some other plugin?

    https://theeventscalendar.com/knowledgebase/k/testing-for-conflicts/

    Let me know what you found on this test

    Cheers,

    Thread Starter davidsonh

    (@davidsonh)

    Thanks for the reply Deblyn!

    I was out of the office between November 25 to December 6. I had been routinely checking the PHP error logs prior to my time off to troubleshoot a different plugin. I did not see the WordPress database error codes I posted prior to my time off. I first noticed them yesterday (December 7) when I checked to verify the other plugin was fixed. The widget is currently disabled, but we’re still seeing the WordPress database error I originally posted.

    I’ll post again once I run through your Testing for Conflicts procedure.

    Thread Starter davidsonh

    (@davidsonh)

    CORRECTION: I had NOT removed the widget from the header widget area. Upon doing so, the WordPress server error message stopped throwing new log entries.

    I’m working on the Testing for Conflicts procedure in a debug environment with the widget enabled.

    Thread Starter davidsonh

    (@davidsonh)

    UPDATE: Just had the first occurrence of the database error without the widget being active. We currently have a Text widget active, and our Events widget is in the inactive list.

    Thread Starter davidsonh

    (@davidsonh)

    @deblynprado any feedback?

    Thread Starter davidsonh

    (@davidsonh)

    @deblynprado and anyone who reads this. I believe we found the conflict. It seems that a function to allow search functionality for ACF fields from the dashboard search feature was conflicting with The Events Calendar plugin. We found the code here and here’s the function in question:

    /**
     * Extend WordPress search to include custom fields
     * http://adambalee.com
     *
     * Join posts and postmeta tables
     * http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
     */
    function cf_search_join( $join ) {
        global $wpdb;
        if ( is_search() ) {    
            $join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
        }
        return $join;
    }
    add_filter('posts_join', 'cf_search_join' );
    
    /**
     * Modify the search query with posts_where
     * http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where
     */
    function cf_search_where( $where ) {
        global $pagenow, $wpdb;
        if ( is_search() ) {
            $where = preg_replace(
                "/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
                "(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
        }
        return $where;
    }
    add_filter( 'posts_where', 'cf_search_where' );
    
    /**
     * Prevent duplicates
     * http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct
     */
    function cf_search_distinct( $where ) {
        global $wpdb;
        if ( is_search() ) {
            return "DISTINCT";
        }
        return $where;
    }
    add_filter( 'posts_distinct', 'cf_search_distinct' );

    Hopefully this can help lead to a small patch to allow for compatibility with this function. Since we disabled this function, there have been no further occurrences of the error from my original post.

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

The topic ‘WordPress database error’ is closed to new replies.