[resolved] Custom Field? (3 posts)

  1. twilitegxa
    Posted 4 years ago #

    I am trying to add in a custom field onto my function.php page. i have the following:

    <?php echo get_post_meta($post->ID, 'icon', true) ?>

    And it's pulling the first post's icon custom field, but for some reason it ONLY pulls that first post's custom field. Why isn't it pulling each post's custom field, like the other parts of the function do? The other parts of the function pull the title and the description of the post (or it seems like it's an excerpt maybe). Here is the link to the site in question:


    Can anyone tell me how to alter my code to get this to show properly? The above part of the slider pulls the appropriate custom field using the same code.

    It's part of a loop. Maybe this is the problem?

    <div id="controllers" class="clearfix">
    				<?php for ($i = 0; $i < $featured_num; $i++) { ?>
    					<li<?php if ( $i == 0 ) echo ' class="active"'; ?>>
    						<div class="controller">
    							<h3><?php echo get_post_meta($post->ID, 'icon', true) ?><?php echo esc_html( $arr[$i]['titletext'] ); ?></h3>
    							<p><?php echo esc_html( $arr[$i]['description'] ); ?></p>
    				<?php } ?>

    Can anyone tell me how to set this up the right way?

  2. twilitegxa
    Posted 4 years ago #

    I tried doing this:

    $arr[$i]['titleicon'] = get_post_meta($post->ID, 'icon', true);

    and then:

    <h3><?php echo esc_html( $arr[$i]['titleicon'] ); ?><?php echo esc_html( $arr[$i]['titletext'] ); ?></h3>

    But the image is not showing as an image, but rather as the text, which is the URL to the image. Can anyone tell me how to make it display as an image? It is now pulling the right image URL, which appears to be a start.

  3. twilitegxa
    Posted 4 years ago #

    I figured it out! I did this:

    <h3><?php echo $arr[$i]['titleicon']; ?><?php echo esc_html( $arr[$i]['titletext'] ); ?></h3>

    and then put the image tag in each custom field and now it works! Yay! Thanks anyway for the support forum!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.