acf get field from custom post type code example

Example 1: acf add options page to custom post type

if( function_exists('acf_add_options_page') ) {
    
    acf_add_options_sub_page(array(
        'page_title'     => 'Offers Page Content',
        'menu_title'    => 'offers-page-content',
        'parent_slug'    => 'edit.php?post_type=offers',
    ));

}

Example 2: acf looping through post types

<?php 

$posts = get_posts(array(
	'posts_per_page'	=> -1,
	'post_type'			=> 'post'
));

if( $posts ): ?>
	
	<ul>
		
	<?php foreach( $posts as $post ): 
		
		setup_postdata( $post );
		
		?>
		<li>
			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
		</li>
	
	<?php endforeach; ?>
	
	</ul>
	
	<?php wp_reset_postdata(); ?>

<?php endif; ?>

Tags:

C Example