WordPress.org

Ready to get started?Download WordPress

Forums

Taxonomy Images
[resolved] display tax image when used with switch_to_blog (5 posts)

  1. Anointed
    Member
    Posted 2 years ago #

    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

    http://wordpress.org/extend/plugins/taxonomy-images/

  2. Eric Andrew Lewis
    Member
    Posted 2 years ago #

    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>';
    }
  3. Eric Andrew Lewis
    Member
    Posted 2 years ago #


  4. Anointed
    Member
    Posted 2 years ago #

    @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?

  5. Eric Andrew Lewis
    Member
    Posted 2 years ago #

    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.

  6. Anointed
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic