display merged posts from multisite and sort by latest date

Question

i have a code. it works, but not perfectly: every site have the category "noticias" but don’t display posts together ordered by latest date, only as a sequence (blog 1: 3 post order by date, blog 2: 3 post order by date, blog 3: 3 post order by date, etc.) and i want to display all together.

the site: the yellow are from blogs 2-3

enter image description here

the code

$blog_ids = array( 1, 2, 3, );
foreach( $blog_ids as $id ) {
switch_to_blog( $id );
$args = array(
'category_name' => 'noticias',
'post_status' => 'publish',
'orderby' => 'publish_date',
'order' => 'DESC',
'posts_per_page' => '4',
);

$query = new WP_Query( $args );

if( $query->have_posts() ) :
while( $query->have_posts()) : $query->the_post() ; 
?>

<div class="col-md-3 mb-36">
<div class="uc-card card-height--same">

<span class="tag-fixed"><?php $tags = get_the_tags($post->ID);  ?>
            <?php foreach($tags as $tag) :  ?><a class="uc-tag" href="<?php bloginfo('url');?>/tag/<?php print_r($tag->slug);?>"><?php print_r($tag->name); ?></a> <?php endforeach; ?></span>
<div class="uc-card_body">
  <p class="p-size--sm p-color--gray p-text--condensed"><?php //the_date();?></p>
  <h4><?php the_title(); ?></h4>
  <div class="uc-text-divider divider-primary my-20"></div>
  <div class="mt-auto">
    <a href=" <?php echo get_permalink(); ?> " class="uc-btn btn-inline">
      Ver más
      <i class="uc-icon">keyboard_arrow_right</i>
    </a>
      </div>
    </div>
  </div>
</div>

<?php
endwhile;
endif;
wp_reset_postdata();
restore_current_blog();}

I hope you can help me,
greetings!

0
Danilo Munoz 2 months 0 Answers 7 views 0

Leave an answer