I have a problem with custom fields that I have been trying to figure out for a while, but with no luck.
I have a section on the site I'm building that let's the users publish content form the the front end. The users content is stored in several custom fields attached to the post. So far so good, everything works as expected.
The problem I have is to figure out the best way to fetch this content.
The post that the user is publishing is divided in small chunks, they can for example add an image, a text, or a video.
The custom fields are created like this for every piece of information:
custom_text custom_text1 custom_text2 custom_image custom_image1 custom_image2 custom_video custom_video1 custom_video2
... and so on.
The problem is, I can never be sure what the user decides to add to his post, and the custom fields for every post will look something like this:
custom_image custom_text1 custom_image2 custom_video3 custom_text4
It has to be saved this way, for the sorting to work. The content needs to be displayed in the order that the user chose when creating the post.
So, what I need is an advanced custom field loop that loops through these custom fields, and display the content accordingly.
php start loop counter = 0 if custom_text (display custom_text) else if custom_image (display custom_image) else if custom_video (display custom_video) counter++; end loop
I'm thinking that the counter could increase with one every time, and then loop through it all again for number 1, 2 3 etc.
We don't know how many fields will be created, but there will be a maximum of 40 chunks, so the last digit will be 39.
I have experimented a lot, but haven't yet been able to find the solution.
Maybe someone could point me in the right direction?