Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Erfo on "Latest posts with same terms of the current post"

$
0
0

Hi.
Inside of an article, I'd like to show the latest 3 recipes with the same "ingredients" of the current post.
I have this code:

$terms = get_the_term_list( $post->ID, 'ingredients' );
$args = array(
        'posts_per_page' => 3,
        'post_type' => 'recipe',
        'tax_query' => array(
                array(
                    'taxonomy' => 'ingredients',
                    'field' => 'slug',
                    'terms' => array( $terms )
                )
            )
        );
$the_query = new WP_Query( $args );

The variable $terms is not correct, I wrote it for example...

How can I show 3 posts whit the same terms of the current post?
Thanks.


Viewing all articles
Browse latest Browse all 8245

Trending Articles