Home Forums ACF PRO Group CPT Posts by ACF Select Field


Group CPT Posts by ACF Select Field

  • Hello – I have a custom post type, and inside those posts, I have an ACF Select field.

    I’m stuck on a query for being able to grab all of the posts from the CPT and display them grouped conditionally, if there are any posts within any given select value.

    For instance, if there are 2 posts with an ACF Select field selection of Group 1, 1 that is in Group 3, and 3 in Group 7, would output:

    Group 1
    Item 1
    Item 2
    Group 3
    Item 1
    Group 7
    Item 1
    Item 2
    Item 3

    I have it partially working now, but using multiple queries (not as efficient) and without the conditional checks, so not ideal.

    Thanks for any insight

  • What is the current query you are using to get the posts without grouping?

  • Thanks John – I was just in the process of reworking so that I’m using custom taxonomy as opposed to using the ACF field at all for that. Should be good to go now. Appreciate the help.

  • Hey, i’m looking for that same thing. Can you post the solution here? Thanks.

  • @maidus – I wasn’t able to get the query for ACF select values to work, so I ended up doing custom taxonomies added to the post type, then doing individual queries for each. Was using this for populating the Isotope jQuery plugin for filtering products.

    <?php $headstyles = get_categories('taxonomy=mag_filter&post_type=product'); ?>
    <?php foreach ($headstyles as $headstyle) : ?>
    <div class="option" data-filter=".<?php echo $headstyle->slug; ?>"><?php echo $headstyle->name; ?></div>
    <?php endforeach; ?>
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Group CPT Posts by ACF Select Field’ is closed to new replies.