WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created one custom post type which name is villa. In this post type I have added five post and assigned custom field values(mention bellow):

   Post Name        Assigned Fields
1. Chalet Austria   Beachfront
2. Antoinette       Cook Services
3. Soline           Garden
4. Apoline          Private Pool
5. Alexandra        Sea View

After that I have created one custom field using with advance custom field plugin, and custom field name is features.

In features there is five option value:

1. Beachfront
2. Cook Service
3. Garden
4. Private Pool
5. Sea View

Note: Value and text is same.

Now I am trying find all posts that have post_type of 'villa' and value is 'Beachfront, Cook Services, Garden, Private Pool and Sea View'.

My Code is:

$args = array(
    'numberposts' => -1,
    'post_type' => 'villa',
    'meta_query' => array(
        'relation' => 'OR',
                'key' => 'features',
                'value' => '%Beachfront%',
                'compare' => 'LIKE'
                'key' => 'features',
                'value' => '%Cook Services%',
                'compare' => 'LIKE'
                'key' => 'features',
                'value' => '%Garden%',
                'compare' => 'LIKE'
                'key' => 'features',
                'value' => '%Private Pool%',
                'compare' => 'LIKE'
                'key' => 'features',
                'value' => '%Sea View%',
                'compare' => 'LIKE'
$the_query = new WP_Query( $args );

<?php if( $the_query->have_posts() ): ?>
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php endwhile; ?>
<?php endif; ?>

<?php wp_reset_query(); ?>

When I run this code I am not getting anything, only page is reloading.. reloading.. and reloading.. :(

I am expecting this result:

  • Chalet Austria
  • Antoinette
  • Soline
  • Apoline
  • Alexandra
share|improve this question
Could you add the following code: print_r( $the_query ); below: $the_query = new WP_Query( $args ); and post the results that are output to your screen on the page. – Dom Feb 11 '14 at 19:54
Unrelated to your issue, you should use wp_reset_postdata when using WP_Query, wp_reset_query is for query_posts which you should never use – Tom J Nowell Feb 11 '14 at 20:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.