WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] query for custom taxonomy of another blog in multisite (6 posts)

  1. njansen
    Member
    Posted 1 year ago #

    Hi,

    I would like to display on a Post page in blog A information about a post from blob B. Both blogs are in the same wp network. In the template for blog A i just switch to blog B and can access information about the post from blog B through the ID. Unfortunately I can't access custom taxonomy information from blog B. It says taxonomy undefined. switch_to_blog apparently doesn't fully switch to the blog and excludes custom taxonomy. Does anybody know a way to acces the custom taxonomy from another blog in a wp network?

    Any help is appreciated.

    Thanks

  2. grosshat
    Member
    Posted 1 year ago #

    Why do not build a SQL query to fetch the custom taxonomy?

  3. It says taxonomy undefined.

    What code are you using? Can you share?

  4. TiagoPires
    Member
    Posted 1 year ago #

    Using this code I can get posts from a custom post type "staff" registered in blog 1 (the main blog) but taxonomy is ignored returning all "staff" could not get taxonomy to filter results.

    <?php
    global $switched;
    switch_to_blog(1); //switched to main blog
    
    // Get latest Post
    $staff = query_posts(array(
    	'post_type' => 'staff',
    	'posts_per_page' => -1,
    	'destination' => 'nova-zelandia'
    	)
    );
    ?> 
    
    <?php if ( have_posts()) : ?>
    <ul class="posts">
    	<?php while ( have_posts() ) : the_post(); ?>
    		<li><?php the_title(); ?></li>
    	<?php endwhile; wp_reset_query(); ?>
    </ul>
    <?php endif; ?>
    
    <?php restore_current_blog(); //switched back to main site ?>
  5. TiagoPires
    Member
    Posted 1 year ago #

    Note that I tried registering the taxonomy on the blog 2 as well (which is wired) but ideally I would only have this 'destination' tax registered on the blog 1 which I'm trying got get posts form.

  6. TiagoPires
    Member
    Posted 1 year ago #

    It works now! I registered the taxonomy in both blogs event if there is no post-type associated to it in the blog 2.

Topic Closed

This topic has been closed to new replies.

About this Topic