Support

Account

Home Forums General Issues Display values outside the loop

Solved

Display values outside the loop

  • Hi everybody,
    I am coding a theme that uses an archive on a page with a special template. Above the results of the archive (that also means outside of the loop) I want to display the values of some custom fields. (e.g. the value of the field “intro”. I tried to create an additional loop and have the values displayed, but there are no results. Does anybody see a mistake?
    Thanks!
    Raphael
    Here is what I tried last:

    <div class="newsearch_intro">
    		<?php global $post; 
    			$args = array('numberposts'=>'1'); 
    			$custom_posts = get_posts($args);
    			foreach($custom_posts as $post) : setup_postdata($post);
    			the_field('intro');
    			endforeach;
    		?>			
    </div>
  • Your query would get the most recent post by post date. Does this post have a value in that field?

  • Thanks, that is right. And I am not 100% sure if it is really the most recent one. So that might be the cause of the problem. So maybe it would be better to use the ID of the post. That is more specific.

    So it would be like this (?):

    
    $args = array('post_id'=>12345);
  • or you can skip that and just supply ACF with the post ID

    
    the_field('intro', 12345);
    
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.