• Resolved Mihail Semjonov

    (@muxahuk1214)


    Hello..
    I’m making theme and i need to echo cuustom post type.
    I’m making query that will use meta_query.

    in my database ther’s a field called ‘dog’ it’s string value, but that string is something like: “text, some other text, the third text, ” atc.
    so.. the problem is that i want my query to search throught all string in DB and if value is in string then show that post..
    for expample the value well be :’some other text’..
    so if ‘some other text’ contains in “text, some other text, the third text, ” atc. then echo post.
    my code is:

    $email_query = new WP_Query (array (
                'post_type' => $field_of,
                'post_per_page' => -1,
                'meta_query' => array(
                    array(
                        'key' => $select_of,
                        'value' => $select_val,
                        'compare' => 'IN'
                    )
                )
            ));

    I’v tied all COMPARE values that have been writen in WP_QUERY documentation. works with “<=” but if i enter some value that not in that string it steels echo’es all posts..
    Help please! what “compare” should be ?
    may be ther’s a chance making my own “compare” ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Mihail Semjonov

    (@muxahuk1214)

    up

    Hey Mihail,

    I ran into a similar situation this week and what worked for me is the LIKE compare operator and adding the meta_key to the main query. In your case it would be:

    $email_query = new WP_Query (array (
                'post_type' => $field_of,
                'post_per_page' => -1,
                'meta_key' => $select_of,
                'meta_query' => array(
                    array(
                        'key' => $select_of,
                        'value' => $select_val,
                        'compare' => 'LIKE'
                    )
                )
            ));

    Give that a shot.

    Thread Starter Mihail Semjonov

    (@muxahuk1214)

    Hey!!
    Yes you got that! I’t works for me) thanks!!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘how to wp_query – meta_query value string contain in key string ?’ is closed to new replies.