Site logo

Archived topic

Display block element if post meta equals certain value

5 replies · Started by Greg on April 8, 2021

Viewing posts 1–6 of 6

Using GP2.0 is fantastic but I wanted check if there's a way I can display a block element (or hide a container within one) depending on the value of an ACF field (eg. display if ACF = "Yes")? Right now it seems like I can only check whether a field exists, not the value of it.

Hi there,

You can use the "Remove container condition" option in the Container block when it's inside a Block Element. Then choose "No post meta", and input the meta field name.

This will remove the Container if that post meta value doesn't exist.

Let me know if that's what you're after or not :)

That is actually really useful and would work fine for lots of things I have planned.

I think it would still be very useful to have "post meta equals X" so that different post options can be displayed as a drop down. That would allow me to create things that would normally require code.

Would this be in the Display Rules? So the entire Element displays based on a post meta value for the requested page?

I think it would be better on a container level to give more control.

To give you an example, https://collectiveanimalrescue.co.uk/adopt/guineapigs/ has cards based on an animal. There are different styles, colours and icons depending on whether an acf dropdown field is equal to different values.

Being able to show the container depending on post meta value would be incredibly useful.

I also wanted to check whether it would be possible to add the current user meta into this so we could easily create user dashboards with this and acf.

Adding Display Rules like this into the actual Container block would become quite complex, but definitely not impossible. I'll give it some thought :)

Thanks!

This archived topic is closed to new replies.