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
-
Best Content Shortcode Plugin
Damn, this plugin saved my time so much. Simple concept but magnificent results. I love this plugin. It gives so many possibilities. What ever page you create, this plugin is a time saver and a must have! Thank You Eliot Akira!
-
Just brilliant. Great support too.
As a WordPresser who slings HTML + Tailwind CSS, this plugin has been an absolute godsend. I can do complex queries in the front end, and can go further than any ‘Posts Module/Block/Widget’ UI could ever hope for.
-
Amazing plugin.
At a time when many web sites are implemented on templates (wpbakery, Divi, Elementor) that have huge restrictions, this plugin allows you to bypass these restrictions. This plugin deserves your support.
In combination with ACF, it gives us a lot of possibilities. -
Great product and great service!
This is my first experience with this plugin, but I can tell you I will be using it every chance I get moving forward! Great service as well!!
-
I’m SO glad I discovered Loops & Logic!!!
Now I can finally create my own dynamic websites! The possibilities are endless! And if you get stuck; the support is fast, professional and very comprehensive!
From now on I will use Loops & Logic in as many projects as possible so that all content is clear and flexible.
-
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!
<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>
- 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_fieldororderby_field_number - 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. - 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
- 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
.grid-masonry {
-moz-column-count: 1;
-webkit-column-count: 1;
column-count: 1;
-moz-column-gap: 1rem;
-webkit-column-gap: 1rem;
column-gap: 1rem;
}
.grid-masonry .tt-item {
break-inside: avoid;
}
.card {
background-color: #fff;
border-radius: 4px;
box-shadow: 0 3px 0 #f0f1f2;
padding: 1rem;
}
