Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using More Fields plugin, and when I use my functions.php to embed the custom field, I get an odd issue. The field value is followed by a "1"

I use this code:

//Address
add_action( 'woo_post_inside_before', 'my_address' );
function my_address() {
    global $post;
if ( is_single() && in_category('listings') ) { 
        echo more_fields('address', '<h1>','</h1>');
       }
}

But, if I use the following code - their is no "1"

//Address
add_action( 'woo_post_inside_before', 'my_address' );
function my_address() {
    global $post;
if ( is_single() && in_category('listings') ) { 
        echo meta('address');
       }
}

How do I style the above using the echo meta? Or has anyone ever seen the "1" issue?

share|improve this question
add comment

3 Answers 3

up vote 0 down vote accepted

There is no WordPress function called meta(). Try using get_post_custom() (Codex ref) instead. For example:

//Address
add_action( 'woo_post_inside_before', 'my_address' );
function my_address() {
    if ( is_single() && in_category('listings') ) { 
        global $post;
        $meta = get_post_custom();
        echo '<h1>' . $meta['address'] . '</h1>';
    }
}

Note: I'm not sure you need to call global $post; in this context?

EDIT: updated to add HTML tags.

share|improve this answer
    
@chip-bennett - Hey Chip, how do I style it with css tags, classes, etc. such as my h1 example above? (wanting to do it all from functions.php, obviously i could style in the template, but I'm trying to avoid that) –  Jason May 3 '11 at 21:57
    
Simply add the HTML tags to the echo command. See edit. –  Chip Bennett May 3 '11 at 22:05
    
ok, I'll give it a shot - thanks for the help –  Jason May 3 '11 at 22:37
add comment

more_fields() already echos the output for you, you don't have to do this yourself. It returns a boolean indicating whether it could output anything, which is converted to 1 when you echo it.

So just call more_fields(), not echo more_fields() to get the output you want.

share|improve this answer
add comment

This is a hunch because I do not know that plugin, your adding styling tags into the parameters of that function, I doubt that is possible (it might be though).

What happens when you use echo more_fields('address')

What about echo "<h1>" . more_fields('address') . "</h1>";

Or even better:

<h1> <?php more_fields('address'); ?> </h1>

share|improve this answer
    
echo more_fields still returns a "1". –  Jason May 3 '11 at 21:53
    
echo "<h1>.... returns the "1" in the h1 tags but the value is returned without styling –  Jason May 3 '11 at 21:55
    
and the other, I'm not sure how to call that correctly within my functions.php –  Jason May 3 '11 at 21:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.