Hi,
All my pages have advanced custom field called : “Program slug”
I would like to get link to the page that have particular value in that custom field.
For example :
Want to get link to the page that has custom field “Program slug” set to “building-speed”
This code will work?
<?php
// args
$args = array(
'numberposts' => -1,
'post_type' => 'page',
'meta_key' => 'program_slug',
'meta_value' => 'building-speed'
);
// query
$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(); ?>">
<img src="<?php the_field('event_thumbnail'); ?>" />
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query();
Hi @martin
Yes, your code will work for simple text based ACF fields.
For complex fields, the code will be a little different.
Check out this tutorial for more information: http://www.advancedcustomfields.com/resources/query-posts-custom-fields/