Hi @justcarl,
The task isn’t ordinary, so you’ll need to use some of our filters.
I can suggest the following solution:
- Add the $Post$ ‘Title’ field to your View (at the very top)
- Add the following code to your theme, that will do the trick, and replace the file’s name with the current post title
class FileWithPostTitle
{
private string $currentPostTitle = '';
public function __construct()
{
// fixme use your view id instead of '5'
add_filter('acf_views/view/field_markup/view_id=5', [$this, 'maybeModifyMarkup',], 10, 4);
}
/**
* @param \org\wplake\acf_views\AcfView\FieldMetaInterface $fieldMeta
*/
public function maybeModifyMarkup($fieldHTML, $fieldMeta, $fieldValue, $viewId): string
{
$name = $fieldMeta->getName();
switch ($name) {
case '_post_title':
$this->currentPostTitle = $fieldValue;
$fieldHTML = '';
break;
// fixme use your file field name instead of 'file'
case 'file':
// 1. replace the current link label with the stub
$fieldHTML = preg_replace('/(<a[^>]+>)([^<]+)(<\/a>)/', '$1_title_$3', $fieldHTML);
// 2. replace the stub with the current post title
$fieldHTML = str_replace('_title_', $this->currentPostTitle, $fieldHTML);
break;
}
return $fieldHTML;
}
}
new FileWithPostTitle();
Don’t forget to replace the values to yours (see fixme comments).
Best regards.