How to pass the Current Page Slug to Query’s argument? (WordPress)

I have these pages: Germany, Argentina, Brazil. When viewing any of these I need a Custom Loop that queries for News (Custom Post Type) AND queries for Country (Taxonomy).

The page slug is exactly as the taxonomy. How could i pass the page slug as a Variable and insert it as an argument inside a WP Query? Thanks in advance!

<?php $loop = new WP_Query(array

('post_type' => 'news',
'country' => $CurrentPageSlug,   //-------> HELP!
'posts_per_page' => 3)); ?>

<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php endwhile; ?>        

Related posts

Leave a Reply

1 comment

  1. As i understand i think you want to detect the page name, this is how you can do.

    // Return the page name like Germany, Argentina, Brazil
    $pagename = get_query_var('pagename');
    

    Then pass this $pagename in WP_Query arguments.