| Wordpress custom fields from posts on a Page
|
geeklike

msg:4236202 | 11:33 am on Nov 29, 2010 (gmt 0) | Hi, I have a Wordpress blog where I have to echo six custom fields per post on a Page, but when I put in this code:
$catID = 4;
if ($catID) { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=$catID&paged=$paged"); } ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post();?>
(content of page)
<?php endwhile; ?> <?php endif; ?>
...it doesn't do anything. I know I have posts in this category, and I tried this on another blog where it worked, but it doesn't on this one, which is why I'm coming to you. Can anybody help me? Thanks in advance, geeklike
|
londrum

msg:4236205 | 11:46 am on Nov 29, 2010 (gmt 0) | your if statement looks like its missing something. if $catID = 4, then your if statement says
if(4) { blah... try changing it to something like
if($_GET['cat'] == $catID) { blah... or whatever it is that your comparing the $catID to
|
geeklike

msg:4236218 | 12:17 pm on Nov 29, 2010 (gmt 0) | Thanks, londrum, it's posting the entries now. However, I still need it to take the custom values from each of the four posts, and make individual variables, like this:
while ( have_posts() ) : the_post(); echo "var "; echo get_post_meta($post->ID, "var", true); echo " = new GlatLng("; echo get_post_meta($post->ID, "lat", true); echo ","; echo get_post_meta($post->ID, "lng", true); echo ");"; endwhile; Only, this doesn't return anything. Can you help with this?
|
londrum

msg:4236264 | 1:50 pm on Nov 29, 2010 (gmt 0) | what are you trying to do. do you just want
var blah = new GlatLng(0.0000, 1.1111); to print to the screen, or are you actually trying to run that line as code? if you're trying to run it as actual code, then try
while ( have_posts() ) : the_post();
$var = get_post_meta($post->ID, "var", true);
$lat = get_post_meta($post->ID, "lat", true);
$lng = get_post_meta($post->ID, "lng", true);
$$var = new GlatLng($lat, $lng);
endwhile;
|
geeklike

msg:4236269 | 2:01 pm on Nov 29, 2010 (gmt 0) | I'm trying to run it as actual code, yes. It still won't work like that either, though.
|
londrum

msg:4236271 | 2:12 pm on Nov 29, 2010 (gmt 0) | i would test the line first with actual values, rather than variables, to see if it does anything. so get rid of all the variables stuff, and just write in the values you want and run it. e.g.
while (have_posts()) : the_post();
var blah = new GlatLng(51.111111, -0.111111);
endwhile; if that doesn't do what you're expecting then the problem must be elsewhere
|
geeklike

msg:4236403 | 7:22 pm on Nov 29, 2010 (gmt 0) | It did, that's the problem. It used to be just one value, and I'm trying to make it make a new variable per post, but when I do it like this, it shows nothing :(
|
londrum

msg:4236695 | 9:44 am on Nov 30, 2010 (gmt 0) | what's the var custom field for? does that change with every post? try the example from 4 posts ago, but writing in the value of var yourself. then at least you'll know that the lat and lng are working
|
geeklike

msg:4236724 | 11:13 am on Nov 30, 2010 (gmt 0) | It changes for every post, yes. It won't work when I do that, no. In the code, in stead of:
var vm = new GlatLng(0.000,0.000); it says:
var vm = new GlatLng(,); Any ideas how to fix it?
|
londrum

msg:4236789 | 1:06 pm on Nov 30, 2010 (gmt 0) | sounds like there are no values to grab under those names (lat and lng). do... while (have_posts()) : the_post(); $var = get_post_meta($post->ID, "var", true); $lat = get_post_meta($post->ID, "lat", true); $lng = get_post_meta($post->ID, "lng", true); echo $var.'<br>'.$lat.'<br>'.$lng; endwhile; if that doesn't print anything then check that there are actually some custom field values set for those posts under those names. sounds like there isn't.
|
geeklike

msg:4237316 | 12:40 pm on Dec 1, 2010 (gmt 0) | I did, it shows whatever is in the different posts, just not when I try it where I need it :/
|
|
|