@@ -65,12 +65,41 @@ function membros_shortcode($atts)
6565function instrutor_shortcode ($ atts , $ content = null )
6666{
6767 $ atts = shortcode_atts (array (
68- 'nome ' => 'Nome do Instrutor ' ,
68+ 'slug ' => '' ,
69+ 'nome ' => '' ,
6970 'imagem ' => '' ,
7071 'descricao ' => ''
7172 ), $ atts , 'instrutor ' );
7273
73- if (!filter_var ($ atts ['imagem ' ], FILTER_VALIDATE_URL )) {
74+ if (!empty ($ atts ['slug ' ])) {
75+ $ args = array (
76+ 'name ' => $ atts ['slug ' ],
77+ 'post_type ' => 'membro ' ,
78+ 'post_status ' => 'publish ' ,
79+ 'numberposts ' => 1 ,
80+ );
81+ $ membros = get_posts ($ args );
82+
83+ if ($ membros ) {
84+ $ membro = $ membros [0 ];
85+ if (empty ($ atts ['nome ' ])) {
86+ $ atts ['nome ' ] = get_the_title ($ membro ->ID );
87+ }
88+ if (empty ($ atts ['imagem ' ])) {
89+ $ atts ['imagem ' ] = get_the_post_thumbnail_url ($ membro ->ID , 'full ' );
90+ }
91+ if (empty ($ atts ['descricao ' ])) {
92+ $ atts ['descricao ' ] = get_the_excerpt ($ membro ->ID );
93+ }
94+ }
95+ }
96+
97+ // Valores padrão se ainda estiverem vazios
98+ if (empty ($ atts ['nome ' ])) {
99+ $ atts ['nome ' ] = 'Nome do Instrutor ' ;
100+ }
101+
102+ if (!empty ($ atts ['imagem ' ]) && !filter_var ($ atts ['imagem ' ], FILTER_VALIDATE_URL )) {
74103 $ img = get_page_by_title ($ atts ['imagem ' ], OBJECT , 'attachment ' );
75104 if ($ img ) {
76105 $ atts ['imagem ' ] = wp_get_attachment_url ($ img ->ID );
0 commit comments