I created a cpt and customized taxonomy related to it. Let’s imagine customized taxonomy title is Sports activities. I added phrases to it – soccer, basketball.
Now, i wish to fetch submit titles tagged underneath soccer and basketball individually on similar web page.(Be aware:- i’m utilizing a customized web page template to point out record of articles from CPT).
$args = array(
'post_type' => 'sports activities',
'tax_query' => array(
array(
'taxonomy' => 'sports_category',
'area' => 'slug',
'phrases' => 'soccer'
),
),
);
$myquery = new WP_Query($args);
So, i’ve efficiently fetched posts for soccer, but when i wish to fetch posts for basketball, do i’ve to create one other question with ‘phrases’ => ‘basketball’?
Is there anyway to move ‘phrases’ dynamically in WP_Query together with set $args in order that i haven’t got to write down similar arguments twice.
What i can consider an answer is making a operate after which storing phrases in a variable which can get its worth from worth handed whereas calling operate.
I wish to know WP particular or environment friendly sokution.