Custom Fields
Re-Envisioned
Support MB Relationships SQL syntax error near '`mbr_order` ASC, mbr_id DESC ASC'

  • Creator
    Topic
  • #28156
    Stefan Grassberger
    Participant

    Hello,
    I'm using versions:

    Meta Box 5.4.0
    Meta Box AIO 1.13.9

    and I'm trying to setup a reciprocal relationship between two terms of a custom taxonomy:

     MB_Relationships_API::register( [
            'id'         => 'rbi_neighboring_countries',
            'reciprocal' => true,
            'from'       => [
                'object_type' => 'term',
                'taxonomy'    => 'rbi_country',
                'meta_box'    => [
                    'title' => 'Neighboring countries',
                ],
            ],
            'to'         => [
                'object_type' => 'term',
                'taxonomy'    => 'rbi_country',
            ],
        ] );

    The code on the archive page:

     <?php
        $terms = get_terms(
            array(
                'taxonomy'     => 'rbi_country',
                'hide_empty'   => false,
                'relationship' => array(
                    'id' => 'rbi_neighboring_countries',
                    'to' => get_queried_object()->term_id,
                ),
            )
        );
        foreach ( $terms as $t ) {
            echo esc_html( $t->name );
        }
        ?>

    This error is displayed in the frontend:
    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'mbr_orderASC, mbr_id DESC ASC' at line 1]
    SELECT t.*, tt.* , mbr.from AS mbr_from, mbr.to AS mbr_to, mbr.ID AS mbr_id, CASE WHEN mbr.to = t.term_id THEN mbr.order_from WHEN mbr.from = t.term_id THEN mbr.order_to END AS <code>mbr_order</code> FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_mb_relationships AS mbr ON (mbr.type = 'rbi_neighboring_countries' AND ((mbr.from = t.term_id AND mbr.to IN (1)) OR (mbr.to = t.term_id AND mbr.from IN (1)))) WHERE tt.taxonomy IN ('rbi_country') <code>mbr_order</code> ASC, mbr_id DESC ASC

    Seems to me like DESC ASC is the issue?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #28177
    Long Nguyen
    Moderator

    Hi,

    Thank you for your feedback.

    I'm going to check this issue and get back to you later.

    #28182
    Stefan Grassberger
    Participant

    Thanks!

    #28389
    Stefan Grassberger
    Participant

    Hi Long,
    were you able to reproduce the issue?

    #28399
    Long Nguyen
    Moderator

    Hi Stefan,

    It was an issue of reciprocal option when using the term object. I've escalated it to the development team to fix it in the next update.

    #28408
    Stefan Grassberger
    Participant

    Great news, thank you so much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.