• Resolved hberger

    (@hberger)


    Does anyone know how to show all custom fields (name AND value) for one post?

    I would like to create a FAQ, and just put the Q&A:s into the custom fields of one post:

    CUSTOM FIELDS
    NAME…………………………………VALUE
    Question 1………………………….Answer 1
    Question 2………………………….Answer 2
    Question 3………………………….Answer 3

    ______________________________________________

    I am using a jquery faq plugin, so I want to have full control of the data. Please help..

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter hberger

    (@hberger)

    Emsi,

    That doesn´t give me both fields. Only one of them + the ID 🙁

    It works perfectly fine. get_post_custom() returns a multidimensional array of ALL custom fields (with keys and values) for a post.

    Thread Starter hberger

    (@hberger)

    Greenshady,

    OK, I´m sorry. But I can´t get it to work.
    Could you please give me the code for echoing “name” and “value”?

    Thread Starter hberger

    (@hberger)

    Someone please help me.

    I have my custom fields like this:

    Custom field “name” Custom field “value”
    Q: How do I contact you? A: You can use our contact form here
    Q: Which way is the……. A: Try this one……..

    And so on. Everything I am able to get is:

    0 => You can use our contact form here
    1 => Try this one……..

    ID and the value field. Not the “name” field.

    This bit of code should work:

    <?php
    $custom_fields = get_post_custom();
    
    foreach ( $custom_fields as $field_key => $field_values ) {
    	foreach ( $field_values as $key => $value )
    		echo $field_key . ' - ' . $value . '<br />';
    }
    ?>
    Thread Starter hberger

    (@hberger)

    Thank you so much, greenshady!

    But I get this as well, in the beginning of the custom fields:

    _edit_lock - 1274798334
    _edit_last - 1

    Is it possible to filter that away somehow?

    Thread Starter hberger

    (@hberger)

    I got it, thanks to a friend:

    $custom_fields = get_post_custom(9);
    
    foreach ( $custom_fields as $field_key => $field_values ) {
    	if(!isset($field_values[0])) continue;
    	if(in_array($field_key,array("_edit_lock","_edit_last"))) continue;
    echo $field_key . '=>' . $field_values[0];
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to get all custom fields (name value)?’ is closed to new replies.