Not working with a custom query
-
Hi Zahlan – I could use some help with customizing your template code to work with a specific template loop (the template file is provided by another plugin and the query is buried in that plugin – I cannot change the query).
I have a Custom Post Type and Custom Taxonomy registered for it. The taxonomy is hierarchical but only so that it appears and is used/checked as a ‘category’ not as a Tag, but there are only ‘parent’ level categories in this custom taxonomy – no child categories. Each custom post has a single (custom) category checked, and each custom category has an image assigned to it using your plugin.
However the template page where I want to display the appropriate category image next to each Post is using a custom query that I cannot modify, and using the “foreach” statement provided in the examples on your documentation page is not working. The template uses the “while have posts” loop.
If I put the “foreach” statement above the “while”, it displays the same category image for every post (the image assigned to the first category ID, even though not every Post is assigned that category ID) and if I put the “foreach” statement below the “while” then it displays an image next to each post that is NOT the appropriate assigned image for the category of the post (interestingly it displays the images in order of their ID number, so for the first post in the list it displays the image assigned to the first category ID, even though that is not the category ID of the post, for the second post it displays the category image assigned to the second category ID, again even though that is not the category of the Post….and so on).
Here is my code:
if ( $query->have_posts() ) { ?> Found <?php echo $query->found_posts; ?> Results<br /> <div> <ul> <?php while ($query->have_posts()) { $query->the_post(); ?> <?php foreach (get_terms('resort_category') as $cat) : ?> <li> <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" width="135" height="135" class="alignleft" /> {some other stuff here} </li> <?php endforeach; } ?> </ul> </div>
- The topic ‘Not working with a custom query’ is closed to new replies.