![]() |
WP Gurus - Help needed
I have a custom field called XYZ with url and I need to put that url in theme template (footer), outside the loop - like this: <a href="XYZ value">some example text</a>
When I call this custom field: <a href="<?php echo get_post_meta($post->ID, 'XYZ', true); ?>">some example text</a> it just shows <a href="current posts permalink">some example text</a> So how to do that properly? :mad: |
if u need to do it outside the loop with post->id u need to do the_post() - you doing that? it shouldn't be showing the permalink though in any case. sure the XYZ value is set up correctly? inside the loop does it show the right value?
if u use the post inside the loop (and always will) why not just do this inside the loop $footerData = get_post_meta(get_the_ID(), 'XYZ', true); (get_the_ID() can be changed with $post->ID...) then in the footer just <?=$footerData;?> it (not checked any code... might be errors) |
Quote:
you will need to pass the actual post id outside the loop for the footer. and if you are changing it each post, i would store the postid in a variable then pass that on to the footer code. |
Ok guys, thank a lot for the info.
I found the solution, maybe someone will find it useful too: Displaying Custom Fields Outside The Loop There are times, when you need to display custom fields outside the loop, e.g., in the footer of the blog post. Displaying custom fields outside the loop will allow you, for example, to have a different footer for each blog post. To achieve, this two things need to be done. 1. Edit the blog post template (e.g., single.php) to make post ID available outside the loop. Find the line Code:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> Code:
<?php $GLOBALS['current_id'] = $post->ID; ?> Code:
<?php echo get_post_meta($GLOBALS['current_id'], "custom-field-name", true); ?> source (through google cache) |
All times are GMT -7. The time now is 02:15 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc