but I would also like to display lists of projects on the basis of custom fields I have set up in the custom post:
I have created a true/false field type with the slug ‘featured-project’ and would like to create a template that only display posts if the field is ticked (ie, true)
I have also created a text field type with the slug ‘project-country’ and would like to create a template that only display posts of one particular country.
I’m guessing (but am not convinced this is right!) that I would start by adding the field name to the loops, like this:
Yes, ACF. And, I think you’re right. Initially I hadn’t intended to filter the posts by country but now I am so I will try taxonomies instead. Good idea.
However, regarding the true/false field type I have set up to select whether it is a featured project or not, this sounds like a sensible approach to me - except I can’t get it to work!
I tried these in the loop, as suggested by Ralf (thanks Ralf):
Hello again. I’ve now changed the project-country custom text field to a taxonomy as discussed above but I am completed confused about how to add this to a template to:
I decided to test this on my end this morning just see if things were working as expected. For starters, I just wrote <Field true_false /> on my template to see what the field itself contained. On my test site, it seemed that when the field was set to true, the value of the field was 1 and when it was false, the value of that field was 0. Is that what you see when you try this on your installation?
Based on that information, I tried creating a filtered loop that looked like this, which worked as expected:
<Loop type=post custom_field=true_false custom_field_value=1>
<p><Field title /></p>
</Loop>
I tried this too, which also worked:
<Loop type=post field=true_false field_value=1>
<p><Field title /></p>
</Loop>
Unless your true/false field is outputting something different than mine (you can check using the method mentioned above), I assume this should work for you too. My only hypothesis about that issue is that in the template you wrote, you seem to have directional quotation marks, like this “ ” instead of regular straight quotation marks like this " ". Is that your issue?
The only difference between this and what I tried yesterday is that there are no quotation marks around the value. Could that be why it didn’t work before? I didn’t use directional quotation marks last time.
Glad it worked! The fact that removing the quotation marks worked seems to indicate that your quotation marks were some non-standard character, although without seeing your exact template I can’t know for sure.
I bet if you copy-pasted this into your template it would work too: field="featured-project" field_value="1"