get_post_meta works / doesn't work
-
Hi,
For some reasons too long to explain, my site open with a short custom template just showing ONE ARTICLE from a given category (the index calls this tiny template with get_template_part and the main loop is not called.
<?php $my_query = new WP_Query('cat=3931&posts_per_page=1'); while ($my_query->have_posts()) : $my_query->the_post(); ?> mini-loop
ALL my articles have several custom fields :
– One is a “subtitle” (letters)
– One is “Numéro” (with an accent !) and contains a number.Here is the strange problem I run into :
I want to show BOTH custom fields.
<?php $subtitle = get_post_meta($post->ID, 'Subtitle', true); echo $subtitle ; ?>
works fine for the first. But the second one, on the same pattern :
<?php $number = get_post_meta($post->ID, 'Numéro', true); echo $number ; ?>
(still with an accent) returns… nothing.
Ah HA ! I already hear you : get rid of the accent, you French moron… That is the source of your trouble.
Alas, no… I have tested the EXACT same code :
<?php $number = get_post_meta($post->ID, 'Numéro', true); echo $number ; ?>
in the loop-single template. AND IT WORKS.
Ive been trying everything I could think of. I don’t understand.
If it was a “in or out of the loop” problem, the first custom field (subtitle) wouldn’t show.
If it was an accent problem, my code would never work. It does when in loop-single.
Please help.
- The topic ‘get_post_meta works / doesn't work’ is closed to new replies.