Viewing 22 posts - 1 through 22 (of 22 total)
  • Author
    Posts
  • #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!
    Ita

    #920255

    Hey 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,
    Ismael

    #920346
    This reply has been marked as private.
    #921012

    Hi Ismael,
    Could you log in on the website with this username and password?

    Cheers,
    Ita

    #921156

    Hi,

    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,
    Basilis

    #921348

    Thank you very much, Basilis! I’ll work on it.

    #923845

    Hi 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!
    Ita

    #924079

    Hi,

    Yes that is true.
    Can you show us with a screenshot exactly where we should see it?

    Best regards,
    Basilis

    #924460

    Hi Basilis,
    I hope these screenshots will give you more information about the problem:

    Default content is visible, bt the content of my meta box not visible in front.
    White screen after adding get_post-meta to includes/loop-index.php

    I eagerly look forward to your solution!

    Cheers,
    Ita

    #926438

    Hi,

    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,
    Ismael

    #926650

    Hi 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!
    Ita

    Btw: 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);

    #927681

    Hi,

    Thank you, most probably because of the copy paste :)
    Let us know if there is anything else we can do for you!

    Best regards,
    Basilis

    #927690

    Hi Badilis,

    Yes, please answer my 2 questions!!

    Cheers,
    Ita

    #928279

    Hi,

    you can paste it on the latest file of the functions.php!

    Best regards,
    Basilis

    • This reply was modified 6 years, 9 months ago by Basilis.
    #928981

    Hi!

    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,
    Ita

    #930151

    Hi,

    Where you want to make those values visible.
    Those print what you add on the boxes!

    Best regards,
    Basilis

    #930615

    Hi,
    Are we now talking about the editing page? Which template would that be?
    Best regards,
    Ita

    #931752

    Hi,

    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,
    Ismael

    #932929

    Hi 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,
    Ita

    #933312

    Hi,

    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,
    Ismael

    #933805

    Hi Ismael!

    That’s what made it work! Thank you very much!!!

    Cheers,
    Ita

    #934102

    Hi ifranl,

    Glad Ismael could help :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

Viewing 22 posts - 1 through 22 (of 22 total)
  • You must be logged in to reply to this topic.