Results 1 to 3 of 3

Thread: Looping post_id to gather records from meta_value

  1. #1
    daniel is offline Hello World
    Join Date
    Sep 2010
    Posts
    5

    Default Looping post_id to gather records from meta_value

    Hi there,
    Can someone help me to create a loop to read all the meta_value records from a given post_id? The idea is to gather all the meta_value's data related to a post_id from the wp_postmeta table and print them as a list.

    I don't have a clue in how to do it.

    Any help will appreciated.

    Thanks

  2. #2
    leewillis77 is offline Hello World
    Join Date
    Oct 2010
    Posts
    22

    Default

    There's a function to retrieve all of a post's meta information :)

    get_post_custom($post_id);

    Documentation here: http://codex.wordpress.org/Function_Reference/get_post_custom

    H
    ope that helps

  3. #3
    daniel is offline Hello World
    Join Date
    Sep 2010
    Posts
    5

    Default

    Hi leewills77,

    Thanks for your help.

    I created the follow shortcode and put it on functions.php, but it doesn't return anything

    Code:
    //Applications list short-code
    
    function jb_applicant() {
    global $wpdb;
    $custom_fields = get_post_custom(2171); //2171 is the post_id that I'm trying to gather the data from
      $my_custom_field = $custom_fields['my_custom_field'];
      foreach ( $my_custom_field as $key => $value )
        echo $key . " => " . $value . "<br />";
    }
    
    
    add_shortcode('applicant', 'jb_applicant');
    Any idea what could be?

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •