I have a loop, and need to pass one more argument through it. I need to get the current page’s single post title, and then use that as the value.

I tried going about it like this:

$tagz = the_title();

$args = array( 
    'post_type' => 'product', 
    'posts_per_page' => 5, 
    'product_tag' => "{$tagz}"  );

and the $tagz variable just automatically echo’s the current post title. I found out through this resource this resource that the_title() merely echos the title and never returns it, making the $tagz variable null.

How can I use the current posts title as an argument? I am really stumped!!

1 Answer
1

You can use get_the_title() to return the current post title in the loop.

Leave a Reply

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