Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

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

<?php if( $the_query->have_posts() ): ?>
    <ul>
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </li>
        <?php endwhile; ?>
    </ul>
<?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 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 at 20:03

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.