Your final outlook is a bit tricky to achieve using traditional way. Lets assume both category has at least 6 post. Now first grab the posts using get_posts()
not WP_Query
$side_news = get_posts(array(
'post_type' => 'post',
'category_name' => 'category-slug-1',
'posts_per_page' => 6
));
$side_news2 = get_posts(array(
'post_type' => 'post',
'category_name' => 'category-slug-2',
'posts_per_page' => 6
));
now that we know we have 6 post each let’s merge the result as alternative position.
$c_result = array();
while(!empty($side_news) || !empty($side_news2)) {
if(!empty($side_news)) {
$result[] = array_shift($side_news);
}
if(!empty($side_news2)) {
$result[] = array_shift($side_news2);
}
}
Now we have an array with 12 posts. Let’s loop through it and achieve the final layout:
echo '<div class="row m-0">';
$i = 0;
foreach ($c_result as $post) {
$i++;
$id = $post->ID;
$title = $post->post_title;
$content = $post->post_content;
if($i%2 == 0):
echo"<div class="col-8">$id $title $content</div>";
else:
echo"<div class="col-4">$id $title $content</div>";
endif;
}
echo '</div>';
get_posts()
returns post as object with following keys:
WP_Post Object
(
[ID] =>
[post_author] =>
[post_date] =>
[post_date_gmt] =>
[post_content] =>
[post_title] =>
[post_excerpt] =>
[post_status] =>
[comment_status] =>
[ping_status] =>
[post_password] =>
[post_name] =>
[to_ping] =>
[pinged] =>
[post_modified] =>
[post_modified_gmt] =>
[post_content_filtered] =>
[post_parent] =>
[guid] =>
[menu_order] =>
[post_type] =>
[post_mime_type] =>
[comment_count] =>
[filter] =>
)