Home › Forums › General Issues › Query posts by custom fields › Reply To: Query posts by custom fields
Hi @renee
I believe you were talking about the current page slug where it shows the custom post type, right? In this case, I think you can get the current page slug like this:
global $post;
$page_slug=$post->post_name;
After that, you need to convert the page slug to the value you want like this:
if( $page_slug == "slug1" ){
$value = "value1";
}elseif( $page_slug == "slug2" ){
$value = "value2";
}else{
$value = "value3";
}
Then you can use it like this:
array(
'key' => 'product',
'value' => $value,
'compare' => '=',
),
I hope this makes sense 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.