query post category based on page title
-
I wanted to query posts in a page template that were associated with each specific page that loaded the template. Started by going down the path of trying to create page categories to match up with post categories. This seemed easier, creating a post category that matches a page title and querying that category. Played around for awhile, thought this might save someone some time so I’m sharing.
<?php $titleCat = get_the_title(); $pageCat = get_cat_ID($titleCat); $pagePosts = new WP_Query( array( 'cat' => $pageCat )); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘query post category based on page title’ is closed to new replies.