Ah right, I see! Thank you very much for all the information and the demo setup. I think I understand it a lot better now so hopefully I won't make a similar mistake in the future. You've now set up the Elementor template to show exactly what I was expecting on each of the CPTs. Thank you for that.
I have one more question leading from this if it's ok to ask.
Imagine I had a large amount of data. For example 5000 different "Types" that could be selected, therefore 5000 different URLs that could be displayed. How could I go about doing this without having to manually generate the code from Views each time and updating the template?
Is there any solution that I can use so as I add different "Types", the URLs are always displayed without having to update any templates?
If it would be easier to have access to explain, please send the private form and I will reinstate the login credentials tomorrow if you.
I assume this is a theoretical question, because creating 5000 field groups and managing those on the wp-admin side will be a challenge. Using a select field with 5000 options on the front-end of the site will be a challenge as well. Nevertheless, I think I would not use conditionals at all. I would use the selected type field value, or content, as a variable in my template. For instance, the Type select field options would be:
Text: "Type 1", Content: 1
Text: "Type 2", Content: 2
Text: "Type 3", Content: 3
...and so on.
You can use the Types field shortcode to access the content of the selected option, like this:
[types field='type' output='raw'][/types]
Now replace the Type number in your code with the shortcode above:
Type [types field='type' output='raw'][/types] Link: [types field="type-[types field='type' output='raw']-link"][/types]
Notice in the Link we are nesting one Types field shortcode inside the slug attribute of another. This approach will only work if the URL field slugs are consistent, where only the number changes.
More information about Types field shortcodes:
https://toolset.com/documentation/customizing-sites-using-php/functions/#select
I am going to need to put something similar into practise, but 5000 was a huge exaggeration. What I should have said is 50!
Thank you for these instructions. I have set up a test on my website and it works well.
Is there any alternative I could use if the fields were not consistent or numerical? As they likely won't be.
Is there any alternative I could use if the fields were not consistent or numerical?
If they are consistent but not numerical, yes. If they are neither consistent nor numerical, then no.
You could modify the content of each option in the Type select field to use some unique text, it doesn't have to be a number. I would recommend using lowercase letters and numbers, no spaces or special characters. Then use the same string in the slug of the corresponding URL field.
I can't think of a practical way to accomplish such a dynamic conditional without some sort of consistent slug structure. It would require custom code where you create an array of slug / slug pairs using PHP, and it's unmanageable because any time you want to add a new type you must update that array. It would be more practical to rethink how you have this set up.
If you're building this from scratch, there's really no reason the field slugs can't be consistent. When you create a field, you give it a consistent field name. Save it, then edit the field and give it a different User-friendly field name. See the attached screenshot. Notice the difference between Field Name and Field Slug.
Thank you Christian.
I will have a rethink to structure this to make my life easier in the future. I think your consistent slug idea is the way forward!
Many thanks again.