CS Forms: Filter not working

Hi,

I used the example from the YouTube video regarding the filtering of the post but this isn’t working. I am displaying a custom post type archive, which shows up fine. I add the as in the video and connect with the post container ID. I can see the Loading UI but the posts do not filter.

I was using Search and Filter Pro prior and have now deactivated the plugin but still doesn’t work.

Any pointers will be appreciated. Thanks.

Hello @web_wa,

Thanks for writing to us.

In order to help you with your concern, please share your details in a secure note. Please provide the following details

  • WordPress Login URL
  • Admin-level username and password
  • Exact page URL

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

Thanks

I have added the info. It would be good to add Sort By field as well in addition to Filter by. Thanks for your help.

Check the the CPT filter field General: Name value in your CS form.
It must match EXACTLY the ACF field group field name (if not a taxonomy)
or
If the filter is for an ACF field group field linked to an ACF Taxonomy, then use the ACF Taxonomy key not the ACF field group field name.

1 Like

Hey @web_wa,

The filter only applies to Taxonomies. It cannot be used with a custom field.
image

If you noticed, there are several “DWER” entries in the dropdown. This should only display unique items.

Thanks.

Hi,
Thanks for looking into it. What about the “Location” and “Topics” Taxonomy. There are populated fine in the Select box but does not filter the results when selected. The “Year” field filters the results fine and it is a ACF field.

Also, how to configure the “Select” field so that it does not select anything to start off with and had a Placeholder text displayed instead of one of the values from the looper.

Hello @web_wa,

Since this is an archive layout, by default, only the latest items are displayed on the archive page.

The filter only gets triggered as soon as you select in the dropdown. Kindly check the demo I created. It is using this query string:
post_type=publication&tax_query%5B0%5D%5Btaxonomy%5D=publication-location&tax_query%5B0%5D%5Bfield%5D=slug&tax_query%5B0%5D%5Bterms%5D={{ form.data({"key":"location"}) }}&tax_query%5B1%5D%5Btaxonomy%5D=publication-topic&tax_query%5B1%5D%5Bfield%5D=slug&tax_query%5B1%5D%5Bterms%5D={{ form.data({"key":"topic"}) }}&meta_query%5B0%5D%5Bkey%5D=year_published&meta_query%5B0%5D%5Bvalue%5D={{ form.data({"key":"year"}) }}&meta_query%5B0%5D%5Bcompare%5D=%3D&meta_query%5B0%5D%5Btype%5D=NUMERIC

  • Check the URL in the secure note below

Hopw this helps.

Thanks for creating the demo. I can see the query being fired and results returned. Is there a way to not have a value selected in the Select box initially and also would reset the box to nothing when reset button is clicked?

Anyway, thanks for looking into it.

Hi,

How do I setup the query string so that when nothing is selected on the dropdown e.g. when the page first loads, all posts are related. i.e. nothing is filtered for the post type? The query string works well and wish there was a bit more documentation on how to write these. Thanks again.

Hey @web_wa,

Try changing the query string to basic post_type=publication to display all posts of the Publication post type.

Please note that working with the Query String requires WP Query knowledge or working with WP Query. We cannot continue building Query Strings as part of our theme support.

If you need continued Query String support, we’d be happy to provide that in our One service.

Thanks.

1 Like

Hi,

Just to tie everything together - I actually didn’t need to use the Query String for Looper provider and just use the default query provided by archive layout. The main issue was that I wasn’t using the exact name under General>Name for the Select element as @TwoLuckyDucks suggested . This had to match with the name of the taxonomy. So instead of just “location” for the Name, when I changed to “publication-location” filtering worked as intended.

Regarding using ACF field as filter, it is a bit difficult and haven’t been able to do it yet. I might have to turn them in to taxonomy as well so it’s straight forward. AI helper suggested using custom loopers to get the unique entries of the “organisation” ACF field and then using it to populate the Select element. I used this code in the function.php to create a custom looper but just couldn’t get it to populate the Select element. I must be doing something wrong.

//-----------------------------------------------------------------------
//
/**
 * Cornerstone Custom Looper: publication-orgs
 * Returns unique ACF text values from field "organisation" on CPT "publication"
 *
 * Use in Cornerstone Looper Provider: Custom → publication-orgs
 */

add_filter('cs_looper_custom_publication-orgs', function($result, $args = []) {

  // 1) Pull all Publication IDs
  $ids = get_posts([
    'post_type'      => 'publication',
    'post_status'    => 'publish',
    'posts_per_page' => -1,
    'fields'         => 'ids',
    'no_found_rows'  => true,
 ]);

  // 2) Collect org values (ACF text field)
  $values = [];
  foreach ($ids as $post_id) {
  // ACF stores text in post meta with the field name as meta key
   $org = get_post_meta($post_id, 'organisation', true);
   if ($org !== '') {
      $values[] = trim((string) $org);
    }
  }

  // 3) De-dupe + sort
  $values = array_filter($values, fn($v) => $v !== '');
  $values = array_values(array_unique($values, SORT_STRING));
  sort($values, SORT_NATURAL | SORT_FLAG_CASE);

  //4) Return array of objects so you can bind label/value easily
  return array_map(fn($v) => ['label' => $v, 'value' => $v], $values);
}, 10, 2);

Is there a way to daisy chain the filter so that if you select the a top filter, the other filter will only show items if they are available with the new filter results?

Hello @web_wa,

You can use the element condition by comparing the field value.
{{dc:form:data key="field_name"}} IS {you key comparison}

When the condition is met, then the element will display.

Hope this helps.

1 Like

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