Use post field with meta_query

Support MB Settings Page Use post field with meta_query

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #16853
    Infolu OfficialInfolu Official
    Participant

    Hello, how can I use the post field to look up words in a specific key instead of just title
    (meta_query = key )

    
    // Register meta boxes and fields for settings page
    add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
        $meta_boxes[] = array(
            'id'             => 'general',
            'title'          => 'Default Domain',
            'settings_pages' => 'ims-core-trades-settings-domain',
            'tab'            => 'general',
            'fields' => array(
                array(
                    'id' => 'url_1',
                    'type' => 'url',
                    'name' => esc_html__( 'URL', 'metabox-online-generator' ),
                ),
                array(
                    'id' => 'post_2',
                    'type' => 'post',
                    'name' => esc_html__( 'Post', 'metabox-online-generator' ),
                    'post_type' => 'domain',
                    'field_type' => 'select_advanced',
                    'query_args'  => array(
                        'post_status'    => 'publish',
                        'posts_per_page' => - 1,
    
                        'meta_query' => array(
                            'relation' => 'AND',
                              array(
                             'key' => 'domain_mf_default_url',
                             'value' => searched word,<-----------
                             'compare' => '=',
                             ),
                         
                         )
    
                    ),
                ),
            ),
        );
        return $meta_boxes;
    } );
    
    #16867
    Anh TranAnh Tran
    Keymaster

    You just need to set compare to LIKE:

    https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

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