Hi,
I have two CPTs, AAA and BBB, related with a one-to-many relationship. AAA is parent. I am creating a custom search view where I want the user to select one BBB and show AAA data.
I would like the user to select the BBB ID or title, but these fields are not available in the filter field list because they are standard WP fields. Why are they not listed ?
I tried to force the field in the filter search code like this:
<div class="form-group">
<label for="wpv-wpcf-post-title">[wpml-string context="wpv-views"]Please select one BBB:[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-post-id" type="select" url_param="wpv-wpcf-post-id"]
</div>
but the select on the page is empty and the view displays all BBBs ...
The simplest alternative is to use a text search field that searches just post titles.
A more complex alternative would involve generating your own filter control for the front-end in the form of a select dropdown that listed the post titles—and a separate one that listed the post IDs if necessary—which added the post ID as a URL parameter.
You could then add a Query Filter for the post ID that listened to that URL parameter.
If you want to try that I can try and guide you, though I can't be sure it will work, we would effectively be hacking an unsupported feature.
Hi Nigel,
thanks for your reply. I might have another workaround. When I create a new BBB record with a specific form and page, I have added a PHP function to set post title = post ID (as suggested by Christian) and it works perfectly. So I have added a new custom field (slug=nr-bbb) and I can use the same function to set it as the ID so that I can use this field for the filter select. The function is the following:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==12345)
// Update the post into the database
wp_update_post( $my_post );
}
}
Although I used the field slug in the PHP function it doesn't work ... the new BBB post is created, but the nr-bbb field is empty. Do I need a special syntax to do this ?? any clue ? thanks
Regards
Nicola