Forums › Forums › Search & Filter Pro › Display ACF fields info for each result
Tagged: results
- This topic has 5 replies, 2 voices, and was last updated 5 years, 8 months ago by
Trevor.
-
Trevor(Private) October 24, 2019 at 7:50 pm #224575
It does, but you need access to the PHP template that the page sues to display the results. If you are using our Shortcode display results method, then follow the guidance here:
https://searchandfilter.com/documentation/search-results/using-a-shortcode/#customising-the-results
There are many examples of accessing ACF field data on the ACF forums on StackExchange. One difference is that you should use
get_the_ID()
to fetch the post ID of each post in the loop, and no reset is used.This search on our forums shows posts with some snippets:
https://support.searchandfilter.com/forums/search/the_field/
Anonymous(Private) October 25, 2019 at 4:41 pm #224680I got it working by using the following code from this page: https://searchandfilter.com/documentation/search-results/custom/
`
$args = array(‘post_type’ => ‘post’);
$args[‘search_filter_id’] = 123;
$query = new WP_Query($args);
`
and then using “the loop” and grabbing the checkbox field for each post:
`
<?php if ( $query->have_posts() ) : ?>
<!– the loop –>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<!– get post tags field –>
<?php $checkbox_fields = get_field(“checkbox_field_name”); ?>
`
Then running a foreach on
$checkbox_fields
to display them or a certain amount of them for each result.Posting this here so people can use this in the future if they want to better control how their results are displayed.
Anonymous(Private) October 25, 2019 at 4:42 pm #224682$args = array('post_type' => 'post'); $args['search_filter_id'] = 123; $query = new WP_Query($args);
and
<?php if ( $query->have_posts() ) : ?> <!– the loop –> <?php while ( $query->have_posts() ) : $query->the_post(); ?> <!– get post tags field –> <?php $checkbox_fields = get_field("checkbox_field_name"); ?>
did my code markup wrong there whoops
-
AuthorPosts