• I’ve installed the ACF plugin and created an field group with two fields: one text field and one image field. I’ve named the fields ad_1 and ad_2 respectively and used <?php the_field(‘ad_1’); ?> and <?php the_field(‘ad_2’); ?> within header.php (after the opening body tag) to display the fields, yet none of the fields display. I also tried it in single.php, nothing.

    I noticed in the Getting started page, it says “Once you have created a field group and saved field data to a $post object, you will need to use PHP code to display that data in your theme.”

    What does “saved field data to a $post_object” mean? Am I missing a step here? Also, am I limited in where I can use the_field? Does it have to be in the loop or can it be anywhere in the body tag?

    I’m going nuts trying to figure this out. Appreciate and help!

    http://wordpress.org/extend/plugins/advanced-custom-fields/

Viewing 1 replies (of 1 total)
  • First copy and past this code in your function.php file

    add_action ('init', 'create_post_type');
    function create_post_type() {
    
    register_post_type('slider_images',
    array(
    'labels' => array(
    'name' => __('Slider Images'),
    'singular_name' => __('Slider Image')
    ),
    'public' => true,
    'has_rewrite' => true,
    'rewrite' => array('slug' => 'slider_images'),
    'supports' => array('title')
    )
    
    );
    }

    Then when you whant to display past this code

    <?php
    			$args = array(
                   'post_type'=>'slider_images',
                   'order'=> 'ASC',
                );
                $i = 1;
    			global $more;
    			query_posts( $args );
    			while (have_posts()) : the_post();
    			$more = 0;
    			?>
    
    <li><img src="<?php echo get_field('image'); ?>"></li>
                    <? endwhile;wp_reset_query();?>
Viewing 1 replies (of 1 total)
  • The topic ‘Custom fields not displaying’ is closed to new replies.