homepage Welcome to WebmasterWorld Guest from 54.145.238.55
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

    
Wordpress custom fields from posts on a Page
geeklike

5+ Year Member



 
Msg#: 4314142 posted 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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4314142 posted 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

5+ Year Member



 
Msg#: 4314142 posted 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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4314142 posted 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

5+ Year Member



 
Msg#: 4314142 posted 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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4314142 posted 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

5+ Year Member



 
Msg#: 4314142 posted 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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4314142 posted 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

5+ Year Member



 
Msg#: 4314142 posted 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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4314142 posted 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

5+ Year Member



 
Msg#: 4314142 posted 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 :/

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved