Support

Account

Home Forums Front-end Issues ACF fields on a static set posts page

Solved

ACF fields on a static set posts page

  • I have set the ‘Posts Page’ within a WordPress site within the “Settings -> Reading’ section to a page called Blog which in the Pages section, has some ACF text fields attached to it for a testimonial to appear on the main blog homepage. I have used ACF across the site however when I type in the testimonial within the admin, the actual content does not appear on the front end of the site and is left blank.

    The issue I have is that if I do not set the ‘Posts Page’ in the settings, the testimonial content appears however the blog posts are lost. Is there a way in which both can work together so that I have have all of the blog posts shown and the ACF’s be seen on the page rather than being left out.

    Any help you be really appreciated.

    Thanks everyone.
    Mark Ferguson

  • When you set the page as a posts page, you’re creating an archive page that is likely using a different template than a single post or page would. It’s possible to show the page’s fields on the posts page, but you would need to manipulate the code in the template that’s getting used.

    The problem is that when you run the loop on the posts page, you’ll get data for the first post, not the page itself. You could get the info about the page with this:
    $query_object = get_queried_object();
    And then you can use the page’s ID to grab the fields from it.

  • Thanks very much for that. I have tried looking into this however I cannot seem to get this working. The Blog page that has been set as the static front page for the Blog has an ID of 11 however I cannot seem to grab any information from this page and display it within this template.

    How would I be able to manipulate:

    $query_object = get_queried_object();

    in order to get the fields I need from the main blog page?

    The code I am using to get the information I need at the moment is:

    <?php
    	$testomonialOneText = get_field( "testomonial_1_text", 11);
    	$testomonialOneAuthor = get_field( "testomonial_1_author", 11);
    	$testomonialTwoText = get_field( "testomonial_2_text", 11);
    	$testomonialTwoAuthor = get_field( "testomonial_2_author", 11);
    	if($testomonialOneText){ ?>
    		<div id="testimonial-one<?php if (isset($testomonialOneText) && $testomonialTwoText == ''){?>-full-width<?php }; ?>">
    			<div class="testimonial"><?php echo the_field( "testomonial_1_text", 11); ?></div>
    			<?php if($testomonialOneAuthor){ ?><div class="testimonial-author"><strong><?php echo the_field( "testomonial_1_author", 11); ?></strong></div>
    		</div><!-- end of #testimonial-one -->
    <?php 
    }};
    	if($testomonialTwoText){ ?>
    		<div id="testimonial-two">
    			<div class="testimonial"><?php echo the_field( "testomonial_2_text", 11); ?></div>
    			<?php if($testomonialOneAuthor){ ?><div class="testimonial-author"><strong><?php echo the_field( "testomonial_2_author", 11); ?></strong></div>
    		</div><!-- end of #testimonial-two -->
    <?php 
    }};
    ?>

    Thanks for your help.

    Mark

  • I’ve just worked out I was using the above code on the template that is attached to the Blog template however when I added the code to the index.php template, the ACF’s were then pulled out from the corresponding ID’s page.

    Thanks for your help.

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

The topic ‘ACF fields on a static set posts page’ is closed to new replies.