Home›Types Community Support›[Resolved] Display CPT profile image using post ID contained in CPT profile image field
[Resolved] Display CPT profile image using post ID contained in CPT profile image field
The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
But the easiest way to insert the image is, when designing the Loop Output section of your View (where you might insert the shortcodes directly, or you might link to a content template where you insert the shortcodes) is to use the Fields and Views button and then select your image field and choose the required settings in the dialog that appears.
I'm not sure what you are currently doing to get it to print the id of the image instead of the image itself.
The office name requires an additional step. I take it that this View shows the Person posts. Offices would be a parent of Persons, yes?
In which case, to output the name of the Office (presumably the post title) you need to add the id attribute to the wpv-post-title shortcode so that it knows to output content from the parent Office post and not the current Person post being iterated over in the Loop.
If your Office CPT has a slug of "office" then you would do that like so: <wpv-post-title id="$office">
Do you want to try the above and let me know if you have any problems?
Thank you for the thorough reply. The CPTs were not made using Types (I believe they were made with ACF), so this may be adding to the complexity. Here is some further info that will probably help you to help me.
Some background:
We are adding Types and Views to an existing theme that defines several CPTs. So the CPTs are not created in Types, but we are trying to use Views to create custom views with data from those CPTs.
CPT relationships:
There are two CPTs involved in this custom search view
1. Person -- stores attorney profiles including photo, name, office and email.
2. Office -- stores a list of offices with title, description, address, etc.
A Person can have one or more offices. The Person Office field simply contains a post id reference to each office that this person has.
Filters - the filters are added from the Person CPT
Thank you for your assistance Nigel. After reviewing a couple posts regarding custom shortcodes I solved the problem as follows:
1. Created two custom short codes - one to get a link to the image (using the wp_get_attachment_image function and the image id contained in the ACF profile_photo field), and a second short code to get the office title from the office post id contained in the ACF office field
2. Modified the view template as shown below to use the ACF fields as short code function parameters
If the custom fields have been set up with something other than Types then you can't use the types shortcode to render them and are limited to the wpv-post-field shortcode, which renders the raw field content.
That wouldn't be a problem if, for example, the profile photo field stored the image url rather than the post id, as you could construct your image links manually, something like this:
Thanks for the follow-up Nigel. This is very helpful.
I added the shortcodes to child theme functions.php, then used the Toolset->Settings->Front End Content->"Third-party shortcode arguments" setting to manually register them.