ACF Looper text field search

Hello, I am trying to create a looper that picks posts based on the content of an ACF field.

I have a field on my posts called “list” in that list I have a comma separated list of values, such as “1,9,22,76”. I’d like to build a looper that displays all posts with, say, “22” in that field.

Is that possible?

Hi Scott,

Thanks for reaching out!

Would you mind sharing more details about your query? because I am not quite sure on how to achieve your goal. Providing screenshots is a great help.

Thank you.

Hello @marc_a,

Using ACF I have created this field group, containing a field “sdg_list”.

It appears on the post like this, and each post has a list of comma separated numbers

Using php and I display these on the final post like this:

:point_up:that is all fine, but what I want to do now is create a page that shows all of the posts that have specific numbers (in this case SDGs) associated with it. In other words I want to create 17 pages, each will use a looper to display post that contain a specific number in the sdg_list ACF; e.g.
Page 1 would look for “1” the sdg_list of all posts
Page 2 would look for “2” the sdg_list of all posts

Page 11 would look for “11” the sdg_list of all posts

Is that possible? I would imagine it would be some kind of regex capability or similar…?

update: if it helps, I plan to link to it from this page https://wellthatsinteresting.tech/technologies-with-purpose/sustainability-technologies-and-the-sdgs/

Thanks
Scott

Hey Scott,

Thanks for the info. I believe that can be achieved using the Dynamic Content Looper. If you’re not familiar with that yet, please take some time to understand how that works in this video https://www.youtube.com/watch?v=ncnXpRW4G_M&list=PLWPh_GoP7hYWzrfwrzAYL53b8YaQhFhfD&index=9

The tutorial video along with other videos in that playlist will show you how to work with ACF and the Dynamic Content Looper.

Please also give us the following info in a Secure Note so we could see your exact setup.

  • WordPress Login URL
  • Admin username and password

You can find the Secure Note button at the bottom of your posts.

Thanks.

Thanks again for this.
I’m not sure this is it either.
After watching nearly all those videos, I think what I need is a looper built using a wp_query that only pulls back posts that have an ACF field containing a specific value.

So, I have 100 ish pages each with the sdg_list custom field
I want to construct a wp_query using the query string option to say "go get all posts where sdg_list is equal to a certain value, such as “3,4,5,6”

How do I construct that query in X?

This page shows me how to do it in php but I can’t translate that to the string I need in X…

As an example, how would I structure this query in the X interface?

$posts = get_posts(array(
'numberposts'	=> -1,
'post_type'		=> 'post',
'meta_query'	=> array(
	'relation'		=> 'AND',
	array(
		'key'	 	=> 'color',
		'value'	  	=> array('red', 'orange'),
		'compare' 	=> 'IN',
	),
	array(
		'key'	  	=> 'featured',
		'value'	  	=> '1',
		'compare' 	=> '=',
	),
),

));

Hi Scott,

The query builder doesn’t support meta queries, but it will work with Query String if you encode it into an HTTP query string first. Or you can use a custom looper. Here are some examples:

Hope that helps.

Thank you.

Aha! Now I understand the 2nd thread! Ok.

The first link you gave doesn’t work.???

Hi Scott,

Please make sure that you are logged in to check the first link. If you cant, I attached a screenshot in the secure note.

Thank you.

Thanks, the screenshot is very useful, but still can’t access the link when logged in.

Hi Scott,

Glad to help you with this. I have checked the first link and it works for me, can you please try once again by clicking on the link: https://theme.co/forum/t/looper-discussion/80640/14

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.