Hey there,
I have a CPT called “Communities” and another one called “Foro”. These CPTs have a bidirectional relationship and “communities” have another relationship with the users.
I have a query loop of the posts in “foro” with a meta query like this:
The meta key is the relationship of the “foro” to the “communities” and then I have a dynamic tag as the value for the User relationship to the “Communities”. This allows me for the user to only see the posts in the “foro” that have the same relationship to the “communities” as the user.
Now… If a user is related to more than 1 community, I have a filter for that custom field (relationship foro>communities), but since I had to give all my relationship field a return value of the post ID, the filter only gives me the communities post IDs. I need to have it return post ID or else the query loop won’t work as intended.
Is there a way for the filter to give me the communities Title instead of the ID? I know I can replace the labels, but that would mean to return to the filter any time my client creates a new “community”.
There is a way if you are comfortable using php with this filter
add_filter('bricks/element/settings', function ($settings, $element) {
if ($element->name !== 'filter-select') return $settings;
if ($element->id !== 'kwhsqe') return $settings;
// Use a WP Query here and use results in for-loop to create option labels
$settings['customLabelMapping'] = [
[
'id' => Bricks\Helpers::generate_random_id(false), // generate a random ID, set to false to prevent echoing the ID
'optionMetaValue' => '1043',
'optionLabel' => 'Test automatic: 1043',
],
[
'id' => Bricks\Helpers::generate_random_id(false),
'optionMetaValue' => '48',
'optionLabel' => 'Test automatic: 48',
]
];
return $settings;
}, 10, 2);
This modifies the settings for this particular select field and adds Labels to corresponding MetaValues. You can modify this to query for your Post-type and programmatically add the label.