• Resolved Knut Sparhell

    (@knutsp)


    Just to test if this plugin had any effect, I installed it on a site that has “The Events Calendar” plugin active. There was only one event, a past event. The Events page then stopped displaying the past event(s) below the current (none). On the PHP error log this was written:

    WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ) CAST( wp_tec_occurrences.start_date AS DATETIME ) AS event_date, CAST( wp_te' at line 1 for query SELECT COUNT( DISTINCT( wp_posts.ID, ) ) CAST( wp_tec_occurrences.start_date AS DATETIME ) AS event_date, CAST( wp_tec_occurrences.duration AS DECIMAL ) AS event_duration
    FROM wp_posts JOIN wp_tec_occurrences ON wp_posts.ID = wp_tec_occurrences.post_id
    WHERE 1=1 AND wp_posts.post_type = 'tribe_events' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private'))
    ORDER BY wp_tec_occurrences.start_date ASC, wp_tec_occurrences.duration ASC, wp_posts.post_date ASC
    made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/plugins/the-events-calendar/src/views/v2/default-template.php'), Tribe\Events\Views\V2\Template_Bootstrap->get_view_html, Tribe\Events\Views\V2\View->get_html, do_action('tec_events_before_view_html_cache'), WP_Hook->do_action, WP_Hook->apply_filters, TEC\Events\SEO\Controller->issue_noindex, TEC\Events\SEO\Controller->should_add_no_index_for_list_based_views, Tribe__Repository->count, WP_Query->get_posts, apply_filters_ref_array('posts_pre_query'), WP_Hook->apply_filters, TEC\Events\Custom_Tables\V1\WP_Query\Modifiers\Events_Only_Modifier->filter_posts_pre_query, TEC\Events\Custom_Tables\V1\WP_Query\Custom_Tables_Query->get_posts, WP_Query->get_posts, WP_Query->set_found_posts

    As you can see there is a trailing comma in the DISTINCT expression’s function parameter list, and a missing comma after the COUNT expression, before the CAST expression.

    Each of these simple actions stops the error:

    1. Deactivating this plugin (no side effect)
    2. Deactivating The Events Calendar (lost functionality)
    3. Adding a snippet to a site plugin or theme functions.php:

    \add_filter( 'query', static function( string $query ): string {
    $query = \str_replace( '.ID, ) ) CAST', '.ID ) ), CAST', $query );
    return $query;
    }, 11 );

    Site Health Info:
    wp-core
    version: 6.8
    site_language: nb_NO
    user_language: nb_NO
    timezone: Europe/Oslo
    permalink: /%year%/%monthnum%/%day%/%postname%/
    wp-active-theme
    name: Neve (neve)
    version: 4.0.1
    author: ThemeIsle

    wp-plugins-active (2)
    The Events Calendar: version: 6.11.2, author: The Events Calendar
    Count Pagination Fix for MySQL: version: 1.1.3, author: Team iSide

    wp-server
    php_version: 8.3.6 64bit
    pretty_permalinks: true

    wp-database
    extension: mysqli
    server_version: 8.0.36

    • This topic was modified 1 year ago by Knut Sparhell.
    • This topic was modified 1 year ago by Knut Sparhell. Reason: Typo and formatting
Viewing 1 replies (of 1 total)
  • Plugin Author jorisvst

    (@jorisvst)

    Hi @knutsp,

    Thank you for reporting this issue.
    We’ve just released a new version that includes a fix to prevent invalid MySQL identifiers and resolve the bad SQL syntax.
    Could you please let us know if the issue is now resolved on your end if you disable your custom snippet?

    Thanks!

Viewing 1 replies (of 1 total)

The topic ‘Invalid SQL (report)’ is closed to new replies.