Skip Navigation

[Resolved] Taxonomy/Term Images Question

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by Chris 7 years, 1 month ago.

Assigned support staff: Paweł Pela.

Author
Posts
#232315

Hello,

I am writing in reference to this post here: https://toolset.com/forums/topic/including-a-taxonomy-image-in-a-view/.

This is slick and actually does the trick in displaying the images, however, I noticed a few issues with this, the most noticeable is when viewing a page, the wpadmin bar says "Edit Activity Category" instead of "Edit Page".

I'm not a quality coder by any means but it seems that this shortcode changes some of the wp_query information and I was wondering if there might be a way to prevent this (or a more updated way to get around this problem).

Thanks for the help, this support forum is great.

#232378

Dear Chris,

I can see the problem with the code, actually, that's true. In one place (line 5) it does overwrite the $wp_query.

I haven't tested it, but please try this:

add_shortcode('wpv-taxonomy-image', 'taximage');
function taximage($atts) {
  global $WP_Views, $wp_query;
  $term = $WP_Views ->get_current_taxonomy_term();
  $orig_query = $wp_query; // save the original query
  $wp_query->queried_object = $term;
  $filtered = apply_filters( 'taxonomy-images-queried-term-image', '' );
  $wp_query = $orig_query; // restore the original wp_query
  return $filtered;
}

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Paweł

#232506

Ha! Superb response, you guys here are great. While the code you provided did not work, you totally answered my question and I was able to get back to square one with wp_reset_query(). For everyone else out there, here is the updated code that works:

add_shortcode('wpv-taxonomy-image', 'taximage');
function taximage($atts) {
  global $WP_Views, $wp_query;
  $term = $WP_Views ->get_current_taxonomy_term();
  $wp_query->queried_object = $term;
  $filtered = apply_filters( 'taxonomy-images-queried-term-image', '' );
  $wp_query->queried_object = wp_reset_query(); // restore the original wp_query
  return $filtered;
}