Displaying posts only form a category that has same name as the current page
-
Hi
My theme supports different post types – one of those is portfolio posts. I’m trying to display portfolio posts on a page but only from one specific category – the one that has the same name as the current page.Exaple:
I have portfolio posts in categories: red, green, blue.
I have pages named: red, green, blue.
Now i would like to display on page “red” only post from category “red”.I’m very new to wordpress and making websites in general.
I tried to read a bit about it and found a way to display posts from certain category only:
<?php $the_query = new WP_Query( 'portfolio_category=red' );?>
From there I tried to do this but it doesn’t work:
<?php $the_query = new WP_Query( 'portfolio_category=$pagename' );?>
Here is full code of the page template I’m talking about:
https://pastebin.com/LxetTnUzThank you in advance for help.
- The topic ‘Displaying posts only form a category that has same name as the current page’ is closed to new replies.