WordPress not getting custom field values
-
Sorry to be a bother, good people – I’ve been trying my darndest to figure things out on my own when something goes wrong, but this one has me stumped! Probably got a real simple solution, one that will make me look like a complete novice, but I’m just not seeing it here. I think my brain’s pretty readily given up.
I’ll try to keep this as short as possible, but I’m afraid I’m a bit rubbish with words…
Basically, I’m using the wonderful function created by Shelley Cole, used to allow child categories to inherit the template of their parent. It’s absolutely wonderful and works a treat, but unfortunately, it seems to have caused a wee bit of a problem.
I have a category that, for argument’s sake, we’ll call Gallery X. The template for Gallery X does not contain any post data, and simply pulls a list of its subcategories using get_categories. The output looks something like this when you go to mysite.com/gallery-x
GALLERY X
— Child 1
— Child 2
— Child 3etc…
The child categories are full of posts that use custom fields to generate a thumbnail image and a link to, say, a video on my server, which opens in a Shadowbox window. This worked absolutely perfectly until I set up Shelley Cole’s function – for some reason, WordPress is no longer getting the value of the custom fields ‘gallery_thumbnail’ and ‘gallery_file’. The link to the gallery_file and thumbnail are remaining, quite stubbornly, the URL of the current child category.
Example
You’re in Child 1 of Gallery X. WordPress is displaying what SHOULD be the thumbnail, but instead of mysite.com/url/or/path/to/file-or-thumbnail.mov, both links are mysite.com/gallery-x/child-1, so all you get is a broken image with the alt text and a link to the category you’re already in, helpfully opening in Shadowbox.
I’m pretty stumped here. Using Shelley’s function isn’t VITAL to the inner workings of my website; I could do away with it without losing any functionality, but it makes my life SO much easier than having to assign exactly the same template to the countless child categories over and over again. I would imagine a possible solution would be to somehow modify the function to exclude certain categories, or to work out exactly WHY it’s not pulling the custom fields when it should.
Here’s the markup I’m using on gallery x’s template file to call the list of child categories:
<ul class="list-cat"><?php $categories = get_categories('child_of=68&orderby=ID&order=asc'); foreach ($categories as $cat) { ?> <li class="cat-item"><h2><a href="<?= get_category_link( $cat->cat_ID ); ?>"><?= $cat->cat_name; ?></a></h2> <h4><?= ''.$cat->category_count.' items'; ?></h4></li> <?php } ?> </ul>
And here’s me trying to get the custom fields on one of the child categories:
<li><a class="galthumbs" href="<?php $key="gallery_file"; echo get_post_meta($post->ID, $key, true); ?>" rel="shadowbox;width=500;height=376" title="<?php the_title(); ?>"><img src="<?php $key='gallery_thumbnail'; echo get_post_meta($post->ID, $key, true); ?>" alt="<?php the_title(); ?>" /></a></li>
The URL for the function I’m using is above, but to save your scrollwheels, here it is again. https://brassblogs.com/blog/making-child-categories-recognize-parent-displaysI’m sorry for the super-long message. I wish I knew what was going on here! I thank you in advance for taking the time to read and attempt to understand my mindless babble.
- The topic ‘WordPress not getting custom field values’ is closed to new replies.