• I’m using a code that I’ve had no problems with on normal WP installations to query a custom post type. The function is displayed on the site using a shortcode that returns the results of the query. I’ve attempted to use this same code on a site set up on a multisite network and can’t get any results.

    I’ve even tried using switch_to_blog() and restore_current_blog() within the function but have had no luck in getting my query to show any results.

    Below is the code I’m currently using. I’ve commented out the tax_query for now while debugging it.

    function create_chalk_holders_list( $atts, $content = null ) {
    
        switch_to_blog(2);
    
    	$string = '<div class="products-wrapper chalk-holders">';
    
    	$tax = array(
    		array(
                'taxonomy' => 'productcollection',
                'field' => 'slug',
                'terms' => 'chalk'
            )
    	);
    
    	$args = array(
            'post_type' => 'products',
            //'tax_query' => $tax,
            'meta_key' => 'number',
            'orderby' => 'meta_value',
            'order' => 'ASC',
            'showposts' => 100
        );
    
        $the_query = new WP_Query ( $args );
    
        if ( $the_query->have_posts() ) {
        	while ( $the_query->have_posts() ) {
        		$the_query->the_post();
    
        		// Output for each product
                // Deleted to simplify post
        	}
        } else {
        	// nothing to display
            $string .= get_current_blog_id();
        }
    
        wp_reset_postdata();
    
        $string .= '</div><!-- .products-wrapper .chalk-holders -->';
    
        return $string;
    
        restore_current_blog();
    
    }
    
    add_shortcode( 'show_chalk_holders', 'create_chalk_holders_list' );
  • The topic ‘Custom Post Type Query in Shortcode Gives No Results’ is closed to new replies.