-
AuthorPosts
-
March 1, 2018 at 5:29 pm #919768
Hi team,
I’ve made a custom post type called ‘Infosheet’ by adding code to the functions.php of my child. I added my CPT to a loop in my child-theme and added also the specific template single-infosheet.php.
I’ve made Meta Boxes via the ‘plugin’ metabox.io; you generate code online and paste it also into the functions.php of child-theme. I see the Meta Boxes on my Edit Screen of my CPT’s and it saves the values, so far so good!
But I don’t manage to get the values of the meta boxes visible on the front. I’ve been searching for days (I am not a programmer) and reading all kinds of tutorials, but to my great frustration I don’t succeed.
Could anyone please tell me where (in my single-infosheet.php and/or within /includes/loop-index. php) I need to add exactly which code?
Thank you very much in Advance!
ItaMarch 2, 2018 at 12:00 pm #920255Hey Frans,
Thank you for using Enfold.
Please provide the access to the site so that we can see the metabox code. It is probably using the custom fields. Use the get_post_meta function to retrieve the data.
// https://developer.wordpress.org/reference/functions/get_post_meta/
Best regards,
IsmaelMarch 2, 2018 at 2:19 pm #920346This reply has been marked as private.March 4, 2018 at 12:33 pm #921012Hi Ismael,
Could you log in on the website with this username and password?Cheers,
ItaMarch 4, 2018 at 9:19 pm #921156Hi,
You need to use
to get data on front end, basicly based on what you have created.
So when you have a specific field name, you have to pull it at front end.Best regards,
BasilisMarch 5, 2018 at 9:08 am #921348Thank you very much, Basilis! I’ll work on it.
March 8, 2018 at 12:53 pm #923845Hi Guys,
So I have 2 Meta Boxes made in my functions.php in my child-theme. They’re called (their ID) ‘my-meta-box-1’ and ‘my-meta-box-2’.
Do I understand corrrectly I should put:
get_post_meta( ‘my-meta-box-1’, $key = ”, $single = false )and
get_post_meta( ‘my-meta-box-2′, $key = ”, $single = false )somewhere in /includes/loop-index.php in my child theme? If so, at what line-number exactly? I have tried from various places but get a’ white screen’ without content.
I hope you can give me more clarity so that the content of my meta-boxes can be seen on the front!
Cheers!
ItaMarch 8, 2018 at 9:15 pm #924079Hi,
Yes that is true.
Can you show us with a screenshot exactly where we should see it?Best regards,
BasilisMarch 9, 2018 at 1:00 pm #924460Hi Basilis,
I hope these screenshots will give you more information about the problem:
I eagerly look forward to your solution!
Cheers,
ItaMarch 14, 2018 at 7:05 am #926438Hi,
Thank you for the info.
Instead of creating your own custom fields object, please use the existing object in the theme. Add this filter in the functions.php file.
function avf_builder_boxes_mod($metabox) { $metabox[] = array( 'title' =>__('New Box','avia_framework' ), 'id'=>'box', 'page'=>array('infosheet', 'page'), 'context'=>'side', 'priority'=>'low'); return $metabox; } add_filter('avf_builder_elements', 'avf_builder_elements_mod', 10, 1); function avf_builder_elements_mod($avf_builder_elements) { $avf_builder_elements[] = array( "slug" => "box", "name" => __("Meta Box 1",'avia_framework'), "id" => "metabox_1", "desc" => "A new metabox 1", "type" => "input", "std" => "", "class" => "avia-style", ); $avf_builder_elements[] = array( "slug" => "box", "name" => __("Meta Box 2",'avia_framework'), "id" => "metabox_2", "desc" => "A new metabox 2", "type" => "input", "std" => "", "class" => "avia-style", ); return $avf_builder_elements; }
This filter will create a new module called “New Box” with two input fields. You can add more input fields in the “$avf_builder_elements” array. In a template, you can use this code to render the custom fields.
$box1 = get_post_meta( $post->ID ,'metabox_1', true); $box2 = get_post_meta( $post->ID ,'metabox_1', true); echo $box1; echo $box2;
`
Best regards,
IsmaelMarch 14, 2018 at 3:25 pm #926650Hi Ismael,
Thank you very much for this clear code + explanation about the filter! You helped me enormously with your clear overview
However (I have been struggling for such a long time now), I have 2 more question about rendering:
1. Do I need to put this code in single-infosheet. php or in /includes/loop index. php?
2. And on which part (line number) of that file?Thanks a lot, Ismael!
ItaBtw: I saw a little typo in the code for the template:
$box2 = get_post_meta( $post->ID ,’metabox_2′, true);
instead of
$box2 = get_post_meta( $post->ID ,’metabox_1′, true);March 15, 2018 at 8:53 pm #927681Hi,
Thank you, most probably because of the copy paste :)
Let us know if there is anything else we can do for you!Best regards,
BasilisMarch 15, 2018 at 9:00 pm #927690Hi Badilis,
Yes, please answer my 2 questions!!
Cheers,
ItaMarch 16, 2018 at 9:09 pm #928279Hi,
you can paste it on the latest file of the functions.php!
Best regards,
Basilis- This reply was modified 6 years, 8 months ago by Basilis.
March 19, 2018 at 10:36 am #928981Hi!
Ismael wrote:
In a template, you can use this code to render the custom fields.
$box1 = get_post_meta( $post->ID ,’metabox_1′, true);
$box2 = get_post_meta( $post->ID ,’metabox_2′, true);
echo $box1;
echo $box2;So, on which part (line number) of which specific template-file should I paste this code?
Best regards,
ItaMarch 20, 2018 at 10:53 pm #930151Hi,
Where you want to make those values visible.
Those print what you add on the boxes!Best regards,
BasilisMarch 21, 2018 at 3:12 pm #930615Hi,
Are we now talking about the editing page? Which template would that be?
Best regards,
ItaMarch 23, 2018 at 3:23 am #931752Hi,
Did you duplicate the single.php file and rename it single-infosheet.php file? If so, you can put the rendering codes inside the includes > loop-index.php file as long as you didn’t modify this line.
get_template_part( 'includes/loop', 'index' );
I’m sure you’ll be able to make your way through that file because the variables are basically self-explanatory. If you want to put it below the title, simply look for this line.
echo $title;
Best regards,
IsmaelMarch 26, 2018 at 10:40 am #932929Hi Ismael,
Thank you for your further explanations.
I have placed the code in a new, clean environment but unfortunately I don’t even get meta boxes in my editing screen: see screenshot. What is going wrong?
Best regards,
ItaMarch 27, 2018 at 3:57 am #933312Hi,
Please check the “avf_builder_boxes” and “avf_builder_elements” filters for the “infosheet”. We also added this code in the loop-index.php file.
$box1 = get_post_meta( $post->ID ,'metabox_1', true); $box2 = get_post_meta( $post->ID ,'metabox_2', true); if( get_post_meta( $post->ID ,'metabox_1', true) ) echo $box1; if( get_post_meta( $post->ID ,'metabox_2', true) ) echo $box2;
You should see the meta box value below the post title. See private field.
Best regards,
IsmaelMarch 27, 2018 at 6:28 pm #933805Hi Ismael!
That’s what made it work! Thank you very much!!!
Cheers,
ItaMarch 28, 2018 at 10:33 am #934102Hi ifranl,
Glad Ismael could help :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.