Hello,
I have created a date field with possibility to have multiple values.
Now, I would like to retrieve the number of values that this field have (in a specific post). In fact, I want to construct a table with the list of the dates in columns. So, I need to define how many columns this table should have.
Thanks for your help
Regards
Pat
Dear Pat,
There isn't such a built-in feature within Views plugin, however, you can create a custom shortcode to get the count of multiple instance field, for example:
There is a multiple instance date field "my-date-field" created with Types plugin, you can try these:
1) Add below codes into your theme/functions.php:
add_shortcode('count_instances', 'count_instances_func');
function count_instances_func($atts, $content){
$atts = shortcode_atts( array(
'field' => 0,
'post_id' => get_the_ID(),
), $atts );
$field = get_post_meta($atts['post_id'], $atts['field'], false);
$res = 0;
if(is_array($field)){
$res = count($field);
}
return $res;
}
2) display the count result with above shortcode, like this:
[count_instances field="wpcf-my-date-field"]
Hi Luo,
That's working fine. Now, I would like to built the table part and need to return something like : </td><td></td><td></td><td>
The number of </td><td> sequences depending of the nb of your function.
I have tried but it seems that the </td><td> is not rendered correctly.
Any idea?
Regards
Pat
I assume the original question of this thread is resolved, for the new question, please check the new thread here:
https://toolset.com/forums/topic/build-the-table-part-on-multiple-instances-field/
Thanks Luo,
Works perfectly!
Regards
Pat