Display existing content in custom field on frontend?
- This topic has 10 replies, 2 voices, and was last updated 3 years, 11 months ago by
Testamentum.
-
AuthorPosts
-
April 19, 2021 at 2:14 AM #27359
Testamentum
ParticipantHow can I display existing content in custom fields? In my booking site project I would like to display destination info depending on the chosen hotel. I want to manage destination info in one place (post), so that changes reflect automatically everywhere.
Basically this - in the CPT, under destination info, I would like to have checkboxes with destination names. If I click Toronto, on the frontend there should be displayed the Toronto destination info (Toronto post). And when I update Toronto post, the change is updated in all Toronto destination infos.
April 19, 2021 at 9:55 AM #27369Long Nguyen
ModeratorHi,
To update one field value and apply for all posts, I think you should use the Taxonomy. Toronto or New York ... should be the term and information of this place is the term meta. So when you change the information of a place, it will change on all posts assigned to this term.
April 19, 2021 at 10:42 PM #27393Testamentum
ParticipantThank you for the reply. I did as instructed - or, how I understood it 🙂 I added all the destination infos as custom fields, and it works when I add them to single template in elementor.
But I have two problems now:
1) I cannot display the destination gallery - I added the gallery as Image Advanced post type. What's the correct way to setup the custom field and display the galleries?
2) How would I display custom fields for more than one post? I created a vacation package, and added the hotel fields. it displayed on the frontend when there was just one hotel added. But when I added the second hotel, the fields became blank.
So, if I want to display two available hotels in one package, how do I do that? What's the general logic of letting hthe WordPress know it needs to display fields for all CPT connected with those fields?
April 20, 2021 at 6:04 AM #27408Long Nguyen
ModeratorHi,
-
To show images from the field
image_advanced
, please follow this documentation https://docs.metabox.io/fields/image-advanced/#template-usage -
Custom field saved value against a unique post, if you want to show a field value for many posts, you can create a new term/taxonomy and assign it to many posts as you want.
April 22, 2021 at 2:47 AM #27475Testamentum
Participant- ok, I managed to display the images with that code. But, it only works for the CPT I am creating the single post template.
That is, I added Imagedvanced images to both types of posts - Vacations and Hotels. With the code I can display Vacations images on Vacations single post template.
But how can I display images from Hotels posts on Vacations template? (They are linked in MB Relationships.)
April 22, 2021 at 4:20 PM #27509Long Nguyen
ModeratorHi,
To get the field value from Hotels posts on Vacations posts, you need to pass the third arguments to the helper function
rwmb_meta( 'image_advanced', '', $p->ID );
Follow on the documentation
https://docs.metabox.io/extensions/mb-relationships/#getting-connected-items
https://docs.metabox.io/rwmb-meta/#argumentsApril 22, 2021 at 5:16 PM #27512Testamentum
ParticipantI'm not a developer, but I did manage to follow the advice. I added that last code before the helper function using the insert php plugin, and the images are outputted like I want them, finally.
But I am getting an error above the images:
Warning: Undefined variable $p in C:\xampp\htdocs\elementor\wp-content\plugins\insert-php-code-snippet\shortcode-handler.php(65) : eval()'d code on line 2
Warning: Attempt to read property "ID" on null in C:\xampp\htdocs\elementor\wp-content\plugins\insert-php-code-snippet\shortcode-handler.php(65) : eval()'d code on line 2
This is the code:
<?php
rwmb_meta( 'image_advanced', '', $p->ID );
rwmb_the_value( 'holidayimg', array( 'size' => 'Thumbnail' ) );How can I fix this?
April 23, 2021 at 6:29 AM #27545Long Nguyen
ModeratorHi,
How did you get the connected posts via Relationships? Please get details on this documentation https://docs.metabox.io/extensions/mb-relationships/#getting-connected-items
After showing the content of the connected posts, you can use the helper function to show the image of Hotels posts on Vacations posts.
May 6, 2021 at 2:17 PM #27958Testamentum
ParticipantIs there anything in Metabox like Relationship field type in ACF? This is exactly what I need, this guy is displaying Dealerships info using that (jump to 3:28).
May 6, 2021 at 9:41 PM #27968Long Nguyen
ModeratorHi,
Thanks for your feedback.
Meta Box has the extension MB Relationships or field type post works similar to the relationship field type of ACF in the backend. But we have to use the code to show the info of the relation posts.
I will inform the development team to make it compatible with Elementor and other page builders for easier drag and drop.
May 15, 2021 at 1:06 AM #28196Testamentum
ParticipantThanks, that would be nice. Adding a simpler way of displaying image gallery would also be super helpful.
For what it's worth, if someone's reading this looking for an answer, I managed to solve all the problems in this thread using Elementor custom skin, Advanced Post Queries (free plugin) and ACF.
Everything works with Metabox too, except displaying fields from posts in relation (though, as suggested, it could be done).
-
-
AuthorPosts
- You must be logged in to reply to this topic.