Advanced Custom Fields value in WP_Query
-
I would like to display posts from a certain category on the homepage based on which category is selected by the user in an Advanced custom field select.
I now have the below working code, which shows posts from category ‘Lisbon’, but I would like to replace ‘new WP_Query( ‘category_name=lisbon’ )’ by something like ‘new WP_Query( ‘category_name=[specific advanced custom field value]’ )’
How would I go about doing this? Thanks very much in advance!
<?php
// the query
$the_query = new WP_Query( 'category_name=lisbon' ); ?><?php if ( $the_query->have_posts() ) : ?>
<!-- pagination here -->
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?><h1><?php the_title(); ?></h1>
<?php endwhile; ?>
<!-- end of the loop --><!-- pagination here -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
- The topic ‘Advanced Custom Fields value in WP_Query’ is closed to new replies.