Does anyone know why querying custom fields does not work in the Carrington mobile theme?

I´m using this:

get_post_meta($post, 'key', true)

But the query does not return anything. Anyone know why?

Added code:

while (have_posts()) : the_post();
    $category = get_the_category($post); 

    $title = get_the_title($post->ID);
    $link = get_permalink($post->ID);
    $store = $category[0]->cat_name;
    $volum = get_post_meta($post->ID, '2Volum', true);
    $produsent = get_post_meta($post->ID, '1Produsent', true);
    $pris = get_post_meta($post->ID, '3Pris', true);

    echo '<a href="' . $link . '">';
    echo '<div class="clear offer">';
    echo '<h1 class="alignleft">' . $title . '</h1>';
    echo '<p class="alignright price">' . $pris . '</p>';
    echo '<p class="alignleft clearleft">' .$produsent . '</p>';
    echo '<p class="alignleft">' . $volum . '</p>';
    echo '</div>';
    echo '</a>';

endwhile; // End the loop. Whew. 

$post should be a post ID (so $post->ID if you've got the global $post object in scope)

the function call parameters are:

$id: the id of the post (integer)
$keyname: a string containing the name of the custom field
$single: boolean - true means return a string for the first value, false means an array of all values for the key

The codex page is here: http://codex.wordpress.org/Function_Reference/get_post_meta

You can also try get_post_custom_values($key, $post_id)

Where $key is the 'name' of the custom field you want to retrieve. $post_id is optional, and defaults to the current post.

  • That doesn´t seem to matter – user1635 Nov 20 '10 at 9:48
  • what do you mean? Edit your question, and post more of the code that doesn't seem to work. the function you're using needs a post id, not a post. So, have you tried putting in a postID that you know exists, eg get_post_meta(10,'yourcustomfieldname',true' – anu Nov 20 '10 at 12:49
  • I have tried putting a postID i know exist. That worked. But when I put $post->ID there, it doesn´t. – user1635 Nov 22 '10 at 17:43
  • strange - I've added an alternative way of querying the customfield you want – anu Nov 23 '10 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy