• Resolved Anointed

    (@anointed)


    I use a simple little function below to display a taxonomy image on my custom post-type single.php page.

    $terms = apply_filters( 'taxonomy-images-get-terms', '', array(
    				'taxonomy' => 'feature',
    			) );
    			if ( ! empty( $terms ) ) {
    				print "\n" . '<div class="row">';
    				foreach( (array) $terms as $term ) {
    					print "\n" . '<div class="four columns">';
    					print "\n\t" . '<a href="' . wp_get_attachment_url( $term->image_id ) . '" rel="lightbox unique-woo-feature">' . wp_get_attachment_image( $term->image_id, 'unique-woo-feature' ) . '</a>';
    					print "\n\t" . '<h5>' . esc_html( $term->name ) . '</h5>';
    					print "\n\t" . '<p>' . esc_html( $term->description ) . '</p>';
    					print "\n" . '</div>';
    				}
    				print "\n" . '</div>';
    			}

    This actually works perfect.

    Where I get stuck:

    On my network site, (another blog on the network), I am using the same code within a page only I am adding in
    switch_to_blog() and of course restore_current_blog().

    When I do that, then the taxonomy images will not show up.

    I am able to pull in the post title, content, etc, everything but the function above does not work.

    This tells me that I have the switch to blog setup correctly, but I am missing something when it comes into pulling in custom taxonomy data.

    Any help would be greatly appreciated, as google was no help. Seems not to many people out there using switch_to_blog, esp when combined with tax metadata.

    thanks

    https://www.ads-software.com/extend/plugins/taxonomy-images/

Viewing 5 replies - 1 through 5 (of 5 total)
  • It looks like you will need to flush the cache of the plugin options right after switch_to_blog to fill it with the new blog’s data. To do this just add a call to the function right after switch to blog

    switch_to_blog(4);
    taxonomy_image_plugin_get_associations(true);
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array(
    	'taxonomy' => 'feature',
    ) );
    if ( ! empty( $terms ) ) {
    	print "\n" . '<div class="row">';
    	foreach( (array) $terms as $term ) {
    		print "\n" . '<div class="four columns">';
    		print "\n\t" . '<a>image_id ) . '" rel="lightbox unique-woo-feature">' . wp_get_attachment_image( $term->image_id, 'unique-woo-feature' ) . '</a>';
    		print "\n\t" . '<h5>' . esc_html( $term->name ) . '</h5>';
    		print "\n\t" . '<p>' . esc_html( $term->description ) . '</p>';
    		print "\n" . '</div>';
    	}
    	print "\n" . '</div>';
    }

    Thread Starter Anointed

    (@anointed)

    @ericlewis
    Thanks for the concept.
    I run into the issue that switch_to_blog, is not loading plugin data, so taxonomy_image_plugin_get_associations leads to a fatal error.

    I’m rather new to this, but I keep reading that switch_to_blog does not bring over plugins data etc.

    Is there something stupid simple that I may be missing here?

    anointed, the code worked for me with the extra function. You should make sure that the plugin is activated on both network sites, that could be giving you the error.

    Also show the error please.

    Thread Starter Anointed

    (@anointed)

    Booyah, I was stupid, your right, plugin was not activated on the primary site.

    Thank you!

    This is going to be a nice stopgap for me, although I am absolutely going to switch to your new function when it supports taxonomies. It is just plain so much easier to work with, and as this particular site won’t be huge, scaling is not an issue.

    Thanks again

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Taxonomy Images] display tax image when used with switch_to_blog’ is closed to new replies.