I would like to add in my post the amount of attached files, but only attached by types file field.
Dear Angelo Rocha,
Try use this code:
1. Add this to theme/functions.php
add_shortcode('show_repetitive_count','show_repetitive_count_func');
function show_repetitive_count_func($atts){
$atts = shortcode_atts( array(
'post' => 0,
'field' => ''
), $atts );
if ( empty($atts['post']) || empty($atts['field']) ){
return;
}
$count = types_render_field( $atts['field'], array("id" => $atts['post'], 'separator' => ',') );
$count = explode(',',$count);
return count($count);
}
Usage: [show_repetitive_count post="POSTID" field="FIELDNAME"]
example: [show_repetitive_count post="69" field="my-numeric"]
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.
How would without shortcode?
I would put the counter in my theme, with php.
Dear Angelo Rocha,
Use same function and add this code
$total = show_repetitive_count_func( array('post' => 1, 'field' => 'my-field') );
Don't forget change post id and field name.
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.
Hi, thanks for your help.
It worked, but is still counting the featured image.
I would like count only the types file field.
Dear Angelo Rocha,
Just change 'field' => 'my-field',
my-field to your repetitive field slug.
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.
I make this change. But this code count the featured image as a file field. Sorry for my bad english, i do not know if i'm explaining right.
Ghennadi is not available to handle this issue anymore, I will. I need to request temporary access (wp-admin and FTP) to your site in order to be of better help. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.