Wow! That was it. All I had to do was change get_pages to get_posts and add
'post_type' => 'page',
Thank you so much!!
I have some other loops and functions going on but the fact I can match either one means my loops should be right 😐
Yup Company Field Group > City is a required Text field and State is a required Select field. Can’t even hardcode the values to match both. Again, I can match anything from State or anything from City but not both. It’s been driving me crazy.
Right, based on everything I’ve seen online, my code should work (that’s what you’re saying correct?). I’ve even tried switch the state from a select to a text field to see if it matches that way to no avail.
I’m actually searching for pages not posts. These pages have been assigned a template I named ‘Client Pages’. Each page is a different company (using the same template), which asks them for their city (which is entered by the user) and their state (which is selected from a drop-down) in the wp dashboard. I don’t ever specify that it has to match ‘Client Pages’ in my code because I am happy to search through all pages, not posts, for this information since there are very few pages other than these company pages.
You could ignore the array portion of my original code and replace
$current_city = $exploded_city[0];
$current_state = $exploded_city[1];
with
$current_city = 'Springfield';
$current_state = 'Missouri';
The state select field is simply a list of all US states, i.e.
Alabama
Arkansas
etc
I may have made this more complicated than it needs to be including the array portion of my other function. Let’s make this simpler.
I’m passing a $city and $state variable to this code.
I need to loop through and display all pages that have ACF values equal to these $city AND $state variables. Right now I am able to match ONLY the city or ONLY the state, but not both.
I should clarify only one city, state combination is being passed to it at a time. The way I wrote in the cityarray implies I do want to see both Illinois and Idaho. My bad.
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.