Forums Forums Search & Filter Pro Display ACF fields info for each result

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Anonymous
    #224525

    *I have done a search in these forums for examples, but couldn’t find what I’m looking for. If you can link me to a post with the answer, I’m okay with that.

    Trevor
    #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
    #224680

    I 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
    #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

    Trevor
    #224686

    Thanks for letting me know. I will close this thread for now.

Viewing 5 posts - 1 through 5 (of 5 total)