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

  • ★★★★★
    Fantastic plugin with great support

    Love this plugin, it’s made some trickier parts of my dev process really simple. The support is incredibly helpful.

  • ★★★★★
    Superb! Saved my day with custom post types.

    I created a custom post type to separate a specific kind of post (with custom fields) from the regular blog posts. But I was struggling to find a way to list the available custom post entries in a sidebar and had not found any plugins with the flexibility and formatting control that I needed.

    With this plug-in I was able to create 8-10 lines of shortcoding in a custom HTML widget that listed the most recent posts, showed the date/author of each in a smaller font than the title and finished up with a pagination control allowing the user to scroll through all available posts.

    Superb!

  • ★★★★★
    Amazingly flexible development tool

    Amazingly flexible plugin for building websites quickly and efficiently, looking forward to seeing it evolve.

  • ★★★★★
    Brilliant plugin – theme builder agnostic

    I needed a solution to build dynamic repeaters with my favorite page builder, which hadn’t released support for loops yet. I’ve also been using L&L to tie up loose ends with other builders that can’t handle complex dynamic showcases – and L&L merges perfectly with every builder I’ve tried, without ever glitching out.

    Now I’m finding myself wanting to go back to HTML and CSS with Loops & Logic because it makes theme building super clean – I could probably ditch every other page builder and use my own framework and build literally any type of site, especially that it supports Woo & LearnDash. Talk about the ultimate flexibility!

  • ★★★★★
    Endless possibilities

    The possibilities are endless…

  • ★★★★★
    Just the best

    Custom content was good and powerful, but Loops & Logic brings it to another level! The plugin is very clean, and gives you the opportunity to do a crazy amount of dynamic coding, and is especially useful when you find that “almost perfect” plugin which lacks a feature or two : with L&L, you can most of the time add this feature yourself.

    True, it’s not a drag and drop plugin, and you’ll have to study the documentation and take some time to master it, but the investment is really worth it.

    I’m not doing much with L&L right now, only pretty simple dynamic stuff, but it’s a relief to know it’s there, and as soon as there is something I wish to do that is not included in a plugin’s feature, I’ll always immediately turn to L&L to see if it can be done.
    So far, I’ve never been disappointed 🙂

    Last and not least, this is a free plugin, which is crazy considering all the possibilities it offers!

  • ★★★★★
    Excellent lowcode templating

    Quite a nifty and powerful plugin for lowcode templating 🙂 Saves a ton of development time.

 <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