Skip to content
This repository was archived by the owner on Mar 21, 2023. It is now read-only.
This repository was archived by the owner on Mar 21, 2023. It is now read-only.

Returning only main site posts #3

@vguenichon

Description

@vguenichon

Hi,
I encounter a similar problem with other way like yours to query the network. Maybe you'll have an idea.
I use your class in a shortcode built for Visual Composer.
And it returns only posts from the main site.
Here's the code:

function events_vc( $atts, $content = null ) {
	extract( shortcode_atts( array (
    	'compare' => '>=',
    	'posts_per_page' => '-1',
    	'order' => 'ASC',
    	'el_class' => '',
	), $atts ));

	include_once(TEMPLATEPATH . 'inc/multisite-query.php');
	$all_events = new WP_Query( array(
		'multisite'			=> '1',
		'post_type'			=> 'events',
		'post_status'		=> 'publish',
		'meta_key'	 		=> 'date_debut',
	    'orderby' 			=> 'meta_value',
	    'order' 			=> $order,
	    'posts_per_page'	=> $posts_per_page,
		'meta_query' 		=> array(
	        array(
	            'key'		=> 'date_debut',
	            'value'     => date('Ymd'),
	            'compare'   => $compare == '&lt;' ? '<' : $compare,
	            'type'		=> 'DATE',
	        ),
    	),
	));

	$output = '';
	if ( $all_events->have_posts() ) {
		$output .= '<div class="events-list '.$el_class.'">';
		$output .= '<h4>Test</h4>';
			while ( $all_events->have_posts() ) : $all_events->the_post();
				ob_start();
				get_template_part('components/modules/event');
				$output .= ob_get_clean();
			endwhile;
		$output .= '</div>';
		wp_reset_postdata();
	}
	return $output;
}
add_shortcode( 'events_vc_output', 'events_vc');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions