Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohn Creedon
4,260 PointsWordpress ACF -> querying page templates instead of posts
So basically i have setup advanced custom fields and i want to structure my website so that when i create a page with a page template of say 'topic-page' i would like ACF to add the custom fields to all pages that have a page template of 'topic-page'. In the past i would use the $args array to query the post_type = 'slug' however how do i query a page template?
existing code for querying post types:
$args = array( 'post_type' = 'the name of the post type' ); $args = new WP_Query( $args );
So i would like to modify it to be able to reference fields from a page template
Thanks
1 Answer
Hugo Paz
15,622 PointsHi Yanni,
Could you try this:
$args = array(
'post_type' => 'page',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'your_template_name.php'
)
)
);