Agh this is frustrating. I've been searching for hours on how to do this.
I am creating a WP template that pulls in queries of a category on the page.
My question is how can I make the category in the array dynamically load, whether by slug or whatever, based entirely on what the page title is?
The fancy piece is that it will be three sections on the page via an additional category that also need to be loaded in the template, but those are not dynamic.
So if I can break this down:
Section 1 - TitleCat + Section1Cat
Then
Section 2 - TitleCat + Section2Cat
Then
Section 3 - TitleCat + Section3Cat
That way during content creation, my team can simply click two categories, and the website will automatically put the post excerpts where it needs to go!
It needs to be dynamic so I don't need to build a template for each of the 31 categories the posts are divided into.
EDIT: This is how I was approaching it using ACF. That array can be simply switched out for categories if that's the way to go. Same concept.
<?php $pagecat = $post->post_title; //this copies the page title the page title ?>
<?php
// args
$args = array(
'posts_per_page' => 4,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'page',
'value' => $pagecat,
'compare' => '='
),
array(
'key' => 'section',
'value' => 'Second String',
'compare' => '='
)
)
);
$the_query = new WP_Query( $args );
?>