Hello!
Using types, I've created a custom post type, called condominium(let's call it of A) and I have the post type listings (let's call if of B).
The point is that some listings, that are terrains, doesn't have photos itself, and in this case, I should retrieve an image of the condominium that this terrain is.
In the fields of the condominium, I have added a field to be the desired featured image of that condominium (See image 1, in attach).
In the listing fields, I have added a field to reference a condominium to that listing. (See image 2)
(I know that's also possible to do that with relationships, also, but when you create a new post, the relationship is just possible when you 'publish' or update it, what's a quite annoying for the user that has to fill all the fields of a big amount of listings.)
I have done my website hybrid with types/views and PHP, so my point is to have a PHP function that retrieves that featured image field of a condominium, inside the listing.
I saw with views that the desired shortcode to do this, in my structure is:
[types field='foto-em-destaque' size='full' item='@associar-proprietario.parent' url='true'][/types]
Is there any way to use PHP to set a variable with the value of the shortcode above?
Hello,
I assume we are talking about this case:
Two post types:
- condominium
- listings
One-to-many relationship between post type "listings" and "condominium"
So each "listings" can connect with multiple "condominium" posts, you can follow our document to setup a post query, get related "condominium" posts:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#wp_query-argument-for-querying-by-related-posts
and display those "condominium" post information(image field "foto-em-destaque"):
https://toolset.com/documentation/customizing-sites-using-php/functions/
Hey Luo!
Thanks for your reply.
Actually this relationship doesn't exists it's just a simple field reference, as the shortcode that I mentioned above.
In this case, the post relationship query won't work, since the condominium is not related to the listing, it's just a reference field. or it will?
In your case, I suggest you setup the one-to-many relationship instead of reference field, so you will be able to query related "condominium" posts in a single listings post, see the documents I mentioned above.
My issue is resolved now. Thank you!