I made a template for my page in which I want to post the latest "topic" and to then post "articles" of the same category as this topic so I have to pass this category via a variable, I think.
I hope the code isn't to long
Thanks for any advice!
<div class="empty-topic">
<?php
$args1 = array(
'post_type' => 'topic',
'post_status' => 'publish',
'posts_per_page' => 1
);
$theme = new WP_Query( $args1 );
if( $theme->have_posts() ) :
?> <div class="topic-facts">
<?php
$theme->the_post();
$mytemp = get_the_ID();
$mycat = get_the_category();
?>
<h3 class="topic-title">"Thema: "<?php the_title(); ?></h3>
<p><?php echo get_post_field( 'facts' ); ?></p>
</div>
<?php
wp_reset_postdata();
?>
<?php
else :
esc_html_e( 'No articles have been found!', 'text-domain' );
endif;
?>
<?php
$args2 = array(
'post_type' => 'article',
'cat' => $mycat,
'post_status' => 'publish',
'posts_per_page' => 3
);
I seem to have made some kind of datatype error because when I try to include this template, I get the error: Object of class WP_Term could not be converted to string