Support

Account

Home Forums Front-end Issues Nothing Displays on Frontend

Solving

Nothing Displays on Frontend

  • I am trying with a very basic test and I am not able to display anything. Everything is blank.

    I have 1 page with no content and just trying to display some fields and nothing works. Nothing displays.

    What can the problem be?

    I created a custom post type portfolio with Custom Post Type UI.
    I created a custom field with ACF that can only be used in that custom post type.
    I create one post in portfolio filling the text. (directly in the custom post types portfolio, not in the page)
    I call the text in my template and nothing displays.

    
    <?php get_header(); ?>
    
    <?php the_field('title'); ?>
    
    <?php get_footer(); ?>
    

    What can the problem be?

    Thanks.

  • I will extend this to make it more clear.

    I have 10 custom post types.
    Slide-01
    Slide-02
    Slide-03
    Slide-04
    Slide-05
    And so on.

    Each custom post type has its unique custom fields.

    Slide-01
    – Photo 1
    – Photo 2
    – Photo 3
    – Title
    – Sub Title

    Slide-02
    – Photo 1
    – Photo 2
    – Photo 3
    – Title
    – Sub Title

    Slide-03
    – Photo 1
    – Photo 2
    – Photo 3
    – Title
    – Sub Title

    And so on.

    I will display the 30 images, titles, subtitles, etc… in a single page template as a gallery.

    I will add the content in each custom post type. If I need to change Slide-01 photo 2, I just go to Slide-02 and change photo 2.

    I am not being able to display anything in my page. The only way it works is if I enable things in the page itself, instead of my custom post types. Having to edit 1 single page with 254 fields is not an option, it has to be using the 10 different custom post types, one for each slide.

    How can I make this work so all the content is only added in the custom post types and I can use everything in a single page and calling each element where needed.

    For example:

    <?php the_field('slide_01_title'); ?>
    <?php the_field('slide_01_photo_01'); ?>
    <?php the_field('slide_04_subtitle'); ?>

    And so on. I will place and call each item individually exactly where I need it.

    Can someone please share an example code where I can start and understand how to use it outside the page itself?

    Thanks.

  • All templates for showing single posts must have “The Loop” https://codex.wordpress.org/The_Loop, looking at the first bit of code you posted I am assuming that you do not have this. No, it does not make a hellofalotta sense when there is only one post, but this is WP.

    If you do not have “The Loop” or you want to show fields outside of “The Loop” then you must supply the post ID when using ACF.

    
    // example when using "The Loop"
    if (have_posts()) {
      while (have_posts()) {
        the_post();
        the_field('your-field-name');
      }
    }
    
    
    // example when not in "The Loop"
    $queried_object = get_queried_object();
    $post_id = $queried_object->ID;
    the_field('your-field-name', $post_id);
    
  • Thank you John.

    You are correct, there is no loop, I am not even using the only page it exist. I am adding directly my code to the index.php of my template and the content should be added using the custom post types.

    Enabling ACF in the page itself I can use:

    
    <?php get_header(); ?>
    
    <?php $website_url = get_field('website_url') ?>
    
    //and then
    <?php echo $website_url ['title']; ?>
    
    //to display the link title wherever I want.
    
    <?php get_footer(); ?>
    

    That works only if ACF is enabled in the page itself and adding the content in the page itself as well, which I don’t want.

    I need to add every single content in their respective custom post type. (Slide)

    How should I call all the custom post types that exist so I can use them in my template?

    That is what is not clear to me and it’s driving me crazy.

    As I have “website_url” under the Links Custom type, I have another 300 different ones under the 10 slides custom post types. One for each specific photo, title, subtitle, link etc… in each slide custom post type.

    So I can be very specific to where I want to show each one of them.

    Can you please share a real example of how can I do this?

    Imagine 10 divs and the way to show exactly whatever custom field you want from the 10 custom post types inside them.

    
    <div class="one"><?php the_field('slide_01_title'); ?></div>
    <div class="two"><?php the_field('slide_01_photo_01'); ?></div>
    <div class="three"><?php the_field('slide_04_subtitle'); ?></div>
    <div class="four"><?php the_field('slide_08_title'); ?></div>
    <div class="five"><?php the_field('slide_06_photo_03'); ?></div>
    <div class="six"><?php the_field('slide_06_photo_02'); ?></div>
    <div class="seven"><?php the_field('slide_03_subtitle'); ?></div>
    <div class="eight"><?php the_field('slide_02_photo_01'); ?></div>
    <div class="nine"><?php the_field('slide_07_photo_01'); ?></div>
    <div class="ten"><?php the_field('slide_02_photo_03'); ?></div>
    

    So I can add exactly the information I need to each div, no matter from which custom post type comes. (10 Slides)

    The code to make it work is what I am not able to create.

    Thanks.

  • To show fields from other posts you need to supply the post ID of that post. Sorry, but what you’re doing is not clear to me from your description.

    But you need a way to get the post ID of the post where the ACF content is. This can be done with a query, or a relationship of some kind.

  • Thank you John, that is exactly my question.

    How can I get all the custom fields created under the 10 custom post types to use any of them in my template.

    10 custom post types
    Inside each one of them 6 custom fields.

    So I have 60 custom fields.

    I have 1 page only and I use it with my only template an index.php

    I need something like this:

    <?php get_header(); ?>
    
    <div class="one"><?php the_field('slide_01_title'); ?></div>
    <div class="two"><?php the_field('slide_01_photo_01'); ?></div>
    <div class="three"><?php the_field('slide_04_subtitle'); ?></div>
    <div class="four"><?php the_field('slide_08_title'); ?></div>
    <div class="five"><?php the_field('slide_06_photo_03'); ?></div>
    <div class="six"><?php the_field('slide_06_photo_02'); ?></div>
    <div class="seven"><?php the_field('slide_03_subtitle'); ?></div>
    <div class="eight"><?php the_field('slide_02_photo_01'); ?></div>
    <div class="nine"><?php the_field('slide_07_photo_01'); ?></div>
    <div class="ten"><?php the_field('slide_02_photo_03'); ?></div>
    
    <?php get_footer(); ?>

    So I can have in any div I decide, any custom field from the 60 ones that exist in different custom post types.

    More clear?

    Thanks for your help.

  • Sorry, I don’t understand what you’re trying to accomplish or how the data you’re trying to accomplish it is saved.

    To show fields from multiple posts you need to do a query to get those posts. Then you need to loop over those posts to get the fields on each post. Without some way tell ACF what post to get the values from there isn’t any way to get and display the data.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Nothing Displays on Frontend’ is closed to new replies.