Query posts filtere not working
-
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:
<ul> <li><a href="someurl">Chalet Austria</a></li> <li><a href="someurl">Antoinette</a></li> <li><a href="someurl">Soline</a></li> <li><a href="someurl">Apoline</a></li> <li><a href="someurl">Alexandra</a></li> </ul>
- The topic ‘Query posts filtere not working’ is closed to new replies.