On my post page I am trying to display list of other posts from the same category of the original post. So far I got this and this does not seem to work:

<?php

    $args = array(
        'post_type' => 'article',
        'posts_per_page' => 5,
        'post__not_in' => array( get_the_ID() ),
        'category'     => array( get_the_category() ),
        'meta_query' => array(
                    array(
                    'key' => 'recommended_article',
                    'value' => '1',
                    'compare' => '=='
                        )
                    )
    );
    $query = new WP_Query( $args );

?>

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

<a class="popup-article-picture" href="https://wordpress.stackexchange.com/questions/240089/<?php the_permalink(); ?>" style="background-image: url('<?php the_post_thumbnail_url(); ?>');"></a>
<a class="popup-article-title" href="https://wordpress.stackexchange.com/questions/240089/<?php the_permalink(); ?>"><?php the_title(); ?></a>

    <?php endwhile; endif; wp_reset_postdata(); ?>

2 Answers
2

I’ve found an answer:

<?php

    $cats = get_the_category();
    $args = array(
        'post_type' => 'article',
        'post__not_in' => array( get_the_ID() ),
        'posts_per_page' => 5,
        'cat'     => $cats[0]->term_id,
        'meta_query' => array(
                    array(
                    'key' => 'recommended_article',
                    'value' => '1',
                    'compare' => '=='
                        )
                    )
    );
    $query = new WP_Query( $args );

?>  

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

<!--HTML-->

<?php endwhile; endif; wp_reset_postdata(); ?>

Leave a Reply

Your email address will not be published. Required fields are marked *