get_permalink not retaining values for loop iterations
-
Hello,
I have a peculiar issue that for the life of me I can’t figure out. It’s probably best explained with an example (I’ve simplified the code down to the core issue):
grab a set of product pages
$productGroups = get_post_meta($post->ID, "product_names", true);
example returned values = Item A|68, Item B|129
$productList = explode(",", $productGroups);
example returned values = $productList[0] = Item A|68
example returned values = $productList[1] = Item B|129foreach ($productList as $product) { $pieces = explode("|", $product);
$pieces[0] = Item A
$pieces[1] = 68echo get_permalink($pieces[1]);
the echo is for testing only and displays correct full path to Item A using the post ID of 68:
//localhost/categories/widgets/Item A/Next I want to assign the permalink to an image by inserting it into the href tag
<a href=" <?php get_permalink($pieces[1]); ?> " class="product_display_tray" > echo "<img src='" . get_post_meta($pieces[1], "image_regular", true) . "' />"; </a>
All images load fine however all the href links result in:
//localhost/categories/widgets/
when they should be:
//localhost/categories/widgets/Item A/
//localhost/categories/widgets/Item B/ etc…Any ideas why they aren’t retaining the full path to each item and only keeping the parent directory path?
Thanks in advance!
Cole
- The topic ‘get_permalink not retaining values for loop iterations’ is closed to new replies.