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

  • Creator
  • #28156
    Resolved Stefan Grassberger

    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:

        $terms = get_terms(
                '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, AS mbr_to, mbr.ID AS mbr_id, CASE WHEN = t.term_id THEN mbr.order_from WHEN mbr.from = t.term_id THEN mbr.order_to END AS &lt;code&gt;mbr_order&lt;/code&gt; 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 IN (1)) OR ( = t.term_id AND mbr.from IN (1)))) WHERE tt.taxonomy IN ('rbi_country') &lt;code&gt;mbr_order&lt;/code&gt; ASC, mbr_id DESC ASC

    Seems to me like DESC ASC is the issue?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
  • #28177
    Long Nguyen


    Thank you for your feedback.

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

    Stefan Grassberger


    Stefan Grassberger

    Hi Long,
    were you able to reproduce the issue?

    Long Nguyen

    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.

    Stefan Grassberger

    Great news, thank you so much!

    Long Nguyen


    This issue has been fixed on this commit. Can you please check it and let me know if it works?

    Stefan Grassberger

    I tested with the plugin at the commit and I can confirm it fixes the issue!

    Thank you, looking forward to the next release 🙂

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