Meta_Query with Custom Tables and Orderby

Support MB Custom Table Meta_Query with Custom Tables and OrderbyResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #33438
    Nicholas CoxNicholas Cox
    Participant

    Hi

    I have taken a look at this post https://support.metabox.io/topic/meta_query-with-mb-custom-tables/
    and my first question is there any support for this yet? using custom table meta with wp_query?

    thanks

    #33442
    Long NguyenLong Nguyen
    Moderator

    Hi,

    No, it is not supported to use custom table meta with WP Query. You can query posts by getting the post IDs in the custom table.

    global $wpdb;
    $ids = $wpdb->get_col( "SELECT ID FROM your_table WHERE field1 = 'value1' OR field2 = 'value2'" );
    
    if ( empty( $ids ) ) {
        echo 'There is no posts';
    } else {
        $query = new WP_Query( [
            'post_type' => 'post',
            'post__in'  => $ids,
        ] );
        // Do something
    }
    #33445
    Nicholas CoxNicholas Cox
    Participant

    Hi Long,

    Ok thanks, just checking before I start developing on this. Well thanks for the example but I am after using custom table meta and not the post ID. But I understand that I will have to grab the column values and then reference the post ID.

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