CPT Review Loop with ACF

The reviews on our homepage are saved as a Custom Post Type (reviews) with ACF fields to handle rating and reviewer details.

Preview

  • ★★★★★
    Display an ACF / CPT in a widget

    Thanks for this! It allowed us to replace a huge chunk of code that was tangled up in a Pro theme when we redid a website (in an effort to simplify it). We used the plugin to pull a title, a preview (featured image), a download URL, and a PDF viewer URL from an ACF / custom post type and display all that in a sidebar widget.

  • ★★★★★
    Genius at play

    This plugin is made by absolute geniuses.

    I have used it in a variety of ways with Elementor and it works straight out of the box. Thank you!

  • ★★★★★
    Very useful, even to a beginner

    As a designer (read “person regularly mystified by lines of PHP”) I found this plugin useful in achieving what I could not do with my page builder of choice. I feel like I’m only scratching the surface of what this plugin can do, but am eager to learn more.

  • ★★★★★
    Amazing Tool that changes everything!

    I can’t imagine using WordPress without Loops & Logic. I’ve replaced cumbersome page builder sections with simple and powerful L&L templates that work perfectly with ACF and CPT. The team is brilliant and unbelievably helpful. Thanks!

  • ★★★★★
    Thank you for this great plugin!

    I was looking since days for a way to show and sort lists of custom fields and only with this plugin I could finally manage to create those kind of lists.

  • ★★★★★
    Amazing and seamless

    Thanks for this plugin, it’s great for its simplicity and concept, I love the ACF support.

    Great documentation!

  • ★★★★★
    State of the art conception. An essential plugin.

    Custom Content Shortcode is THE way to go to take control of your WordPress installation if you cannot modify the source code, either because you cannot access it (eg. if your site is hosted on WordPress.com), or because you simply don’t want to.

    These shortcodes are perfectly well thought and designed, they are just coherent and consistent all the way. It just feels like they are a native feature of WordPress.

    Combine with custom post type plugins like WCK and ACF to unlock the full power of WP, without the need to modify a single source file.

 <ul class="grid-masonry">
    <Note>1</Note>
    <Loop type=reviews orderby_field_number=rating order=desc>
      <li class="tt-item card {Field post_class}">
        <div class="content">
          <If field=rating>
            <div class="rating">
              <Note>2</Note>
              <Switch check="{Field acf_radio=rating}">
                <When value="5" />★★★★★
                <When value="4" />★★★★☆
                <When value="3" />★★★☆☆
                <When value="2" />★★☆☆☆
                <When value="1" />★☆☆☆☆
              </Switch>
            </div>
          </If>
          <div class="title"><Field title /></div>
          <div class="description"><Field content /></div>
        </div>
        <div class="footer">
          <Note>3</Note>
          <Set person_content>
            <If field=person_image>
              <span class="avatar"><img src="{Field acf_image=person_image field=url}" alt="{Field person_name}" /></span>
            </If>
            <div>
              <div class="name"><Field person_name /></div>
              <div class="role"><Field person_role /></div>
            </div>
          </Set>
          <Note>4</Note>
          <If field=person_website>
            <a class="author" href="{Field person_website}" target="_blank" rel="nofollow noopener">
              <Get person_content />
            </a>
            <Else />
            <div class="author">
              <Get person_content />
            </div>
          </If>
        </div>
      </li>
    </Loop>
  </ul>
  1. To open a CPT loop, use the Post Type Slug in the type attribute. You can sort the returned posts by a custom field with orderby_field or orderby_field_number
  2. To save a bit of time, you can use Switch/When tags for your logic instead of If/Else. This saves you from having to pass your field to each statement. This rating section could also be written as:
    <If check="{Field acf_radio=rating}" value=1>★☆☆☆☆<Else if check="{Field acf_radio=rating}" value=2 />★★☆☆☆ etc.
  3. Use Set and Get to save pieces of markup for use elsewhere. In this example it’s being used for the inner author content, so that it can be placed into alternate wrappers depending on whether there’s a website link available
  4. When using alternate wrappers, it’s usually best to approach things this way instead of wrapping the opening and closing tags each in their own if statement