meta_query with MB Custom Tables

Support MB Custom Table meta_query with MB Custom TablesResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #8563
    jcleavelandjcleaveland
    Participant

    Hi,

    I am trying to execute a meta_query using the MB Custom Tables extension. I can echo the values from the table just fine and a standard archive works too, but when I try to build a custom query using a meta_query, I get no results.

    Here is the query that works when using the post_meta table but not when using the custom table.

    $query_args = array (
        'post_type'           =>   'obh_note',
        'orderby'         =>   'meta_value',
        'meta_key'            =>   'obh_note_date_time',
        'order'               =>   'ASC',
        'meta_query'              =>   array(
            array(
                'key' => 'obh_note_associated_members',
                'value'   =>   $post->post_author,
                'compare' => 'LIKE',
                )
            )
    );
    
    //The query
    $member_notes = new WP_Query( $query_args );

    Am I missing something?

    Chúc Mừng Năm Mới!!

    #8583
    Anh TranAnh Tran
    Keymaster

    Hi,

    Thanks for the greeting 🙂

    The Custom Table extension hasn't incorporated with the meta query yet. Please use 2 queries to get posts: 1 for getting post IDs from the custom table and one for getting posts. This is the sample code:

    global $wpdb;
    $post_ids = $wpdb->get_col( $wpdb->prepare(
        "SELECT ID FROM your_table
        WHERE obh_note_associated_members LIKE %s",
        $post->post_author
    ) );
    
    $query_args = array (
    	'post_type' =>	'obh_note',
    	'orderby'   =>	'meta_value',
    	'meta_key'  =>	'obh_note_date_time',
    	'order'     =>	'ASC',
    	'post__in'  => $post_ids,
    );
    
    //The query
    $member_notes = new WP_Query( $query_args );
    #8597
    jcleavelandjcleaveland
    Participant

    Perfect. Thank you!

    Any plans to support meta queries in the future?

    #8600
    Anh TranAnh Tran
    Keymaster

    I'm not sure about this, because the way WordPress build SQL queries from meta query object is very complicated. I'll see if I can do something.

    #8604
    jcleavelandjcleaveland
    Participant

    No worries. This will work fine. I was just wondering if I should be planning for something different coming soon.

    Thanks for all your help!

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