Custom Fields
Re-Envisioned
Support MB Custom Table meta_query with MB Custom Tables

This topic contains 4 replies, has 2 voices, and was last updated by  jcleaveland 1 year, 8 months ago.

  • Creator
    Topic
  • #8563
    Resolved
    jcleaveland
    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!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #8583

    Anh 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

    jcleaveland
    Participant

    Perfect. Thank you!

    Any plans to support meta queries in the future?

    #8600

    Anh 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

    jcleaveland
    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 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.