query_posts: how to show all ‘meta_value’ containing a specific word?

How could you display all the post in a loop with a (custom) meta_value containing a word/phrase? for exemple get al the post where meta contains ‘test’.

query_posts('post_type=SOME&category_name_2=SOME&meta_value= 'Cotains the word 'test' ??? '); 

so when the meta tags are ‘test movie’ or just ‘test’ you get them both.?

Related posts

Leave a Reply

2 comments

  1. by Using “Custom select query”

    <?php
    
     $querystr = "
        SELECT wposts.* 
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id 
        AND wpostmeta.meta_key = 'tag' 
        AND wpostmeta.meta_value LIKE '%test%' 
        AND wposts.post_status = 'publish' 
        AND wposts.post_type = 'post'  
        ORDER BY wposts.post_date DESC
     ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    ?>
     <?php if ($pageposts): ?>
      <?php global $post; ?>
      <?php foreach ($pageposts as $post): ?>
        <?php setup_postdata($post); ?>
      <?php endforeach; ?>
     <?php endif; ?>