• Resolved eatanicecream

    (@eatanicecream)


    Does anyone know how to make the output of a custom field – <?php the_meta(); ?> – not display as a list?

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • huggie

    (@huggie)

    Use get_post_custom() instead. This way you can manipulate the response as required with PHP.

    Thread Starter eatanicecream

    (@eatanicecream)

    Tried that first, but it doesn’t actually display the content of my custome field. Any idea why?

    MichaelH

    (@michaelh)

    Review the various aspects of Custom Fields.

    If you continue this thread please show us the code you used that didn’t work based on huggie’s suggestion.

    Thread Starter eatanicecream

    (@eatanicecream)

    Sorry, just trying to make sense of how custom fields work…thanks for the help.

    The page I’m working on is here: https://wdm.org.uk/localgroups/events/

    What I’d like to do is create an events listing page which shows post title and custom field date.

    Putting <?php the_meta(); ?> between the <h4> tags below outputs the custom field but as an unordered list. Putting <?php get_post_custom($post_id); ?> between the <h4> tags outputs nothing, ie just <h4> </h4>.

    ?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    
    <div class="inner">
    
    				<h2 class="eventtitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2><br />
    
    <h4><?php the_meta(); ?></h4>                
    
                    </div>
    MichaelH

    (@michaelh)

    Please review the example in the link huggie provided as well as the link I provided:

    Function_Reference/get_post_custom
    Custom Fields

    Thread Starter eatanicecream

    (@eatanicecream)

    Thanks. Not very good with PHP.

    <?php
    
      $custom_fields = get_post_custom(72);
      $Date = $custom_fields['Date'];
      foreach ( $Date as $key => $value )
        echo $key . " => " . $value . "<br />";
    
    ?>

    Outputs 0 => 15/03/2009.

    How do I get rid of the ‘0 =>’ bit? Got rid of the => but can’t figure out how the 0 is generated.

    MichaelH

    (@michaelh)

    echo  $value . "<br />";
    Thread Starter eatanicecream

    (@eatanicecream)

    Thanks a lot, really appreciate it. Got it all sorted now.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to make custom fields not output a list?’ is closed to new replies.