WP Query and ACF in Looper Provider

I’m trying to create the query string for the WP Query in the Looper Provider. I’d like it to contain ACF fields.

Here are the parameters:

  • Pulls from 2 different Post Types: pilgrimage_pages and pages
  • Order by departure_date (ACF field) descending
  • category_array (ACF field) is a Select field which is returned as an array - The Select item text should equal “poland”
  • Status is published

I have this so far but I can’t figure out how to do category_array:
post_type[]=pilgrimage_pages&post_type[]=page&orderby=meta_value&meta_key=departure_date&order=DES&post_status=publish

Can you please help?

Thanks.

Hello @tektonministries,

Thanks for writing in!

Based on the information you shared, this could be your query arguments:

$args = array(
   	'post_type'    => array('pilgrimage_pages', 'pages'),
   	'orderby' => 'meta_value_num',
   	'meta_key' => 'departure_date',
	'order' => 'DESC',
	'category_name' => 'poland',
	'post_status' => 'publish',
);

You can use the arguments above and run the http_build_query($args) function in your Child theme’s functions.php to get the resulting query string.

Hope this helps.

Thanks. However, category_array is an ACF Select field which is returned as an array - The Select item text should equal “poland”. So I need to get the array and then be able to select the item text.

I have this as a guess:
&meta_query[0][key]=category_array&meta_query[0][choices][value]=poland

However, this appears to only filter that a value exists in that field not that it equals “poland”.

Any ideas?

Hello @tektonministries,

I guess you might need this argument instead:

$args = array(
   	'post_type'		=> array('pilgrimage_pages', 'pages'),
   	'orderby' 		=> 'meta_value_num',
   	'meta_key' 		=> 'departure_date',
	'order' 		=> 'DESC',
	'post_status' 	=> 'publish',
	'meta_query' 	=> array(
			array(
				'key'     => 'category_array',
				'value'   => '{{dc:acf:post_field key="acf_field_name"}}',
				'compare' => 'IN',
			)
);

Hope this helps.

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