Support

Account

Home Forums Front-end Issues Problem to print relationship

Solved

Problem to print relationship

  • I have the following problem:

    I’m following the tutorial methodically acf relationship to print the result of a field on the screen but does not work. Below is the code I’m writing:

    This code is in the single-file mycustomposttype.php

    Question: Should I or not keep the loop or not need the loop?
    What am I doing wrong? None of the applications I tried to do that same code on other pages, it did not work.

    The printed result is in the attached image.

    <?php

    $user = wp_get_current_user();

    if ( ! is_user_logged_in() ) {
    wp_redirect( site_url(‘/’, ‘http’) ); exit;
    }
    if( ! current_user_can(‘administrator’) ){
    wp_redirect( site_url(‘/sistema’, ‘http’) ); exit;
    }

    acf_form_head();
    get_header();
    the_post();
    //add_thickbox();
    ?>

    <?php get_template_part(‘sistema/parts/cabecasistema’);?>

    <section class=”margin30 clearfix”>
    <div class=”wrap “>

    <div class=”titpagesis clearfix”><span class=”iconetitpagesis”><i class=”flaticon-book201″></i></span> Servidor <span class=”aux-item”><i class=”vermelho flaticon-pencil102″ id=”editar”></i><i class=”print vermelho flaticon-printer87″></i></span></span></div>

    <div class=”col640 border-bottom border-top margin-top fleft “>

    <div class=”conteudo-sis relative clearfix “>
    <div class=”dados item-sis clearfix”>

    <?php //$the_query = new WP_Query( array(‘post_type’ => ‘servidores_post’, /*’posts_per_page’ => 1 ‘p’=> $post_id, */’post_status’ => array( ‘pending’, ‘publish’) ) ); ?>

    <?php //while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    <h2><?php the_title(); ?></h2>
    <div class=”foto-serv”>” /> <div class=”mask-download”>” target=”_blank” download=”<?php the_title(); ?>”><span class=”icon”><i class=”flaticon-down90″></i></span></div></div>
    <h3>Dados Pessoais</h3>
    <p>CPF: <?php the_field(‘cpf_do_servidor’); ?><br>
    Sexo: <?php the_field(‘sexo_do_servidor’); ?><br>
    Data de nascimento: <?php the_field(‘data_de_nascimento_servidor’); ?><br>
    Estado civil: <?php the_field(‘estado_civil_servidor’); ?><br>
    RG: <?php the_field(‘rg_servidor’); ?> <?php the_field(‘og_rg_servidor’); ?>-<?php the_field(‘uf_og_rg_servidor’); ?><br>
    Título de eleitor: <?php the_field(‘titulo_de_eleitor_do_servidor’); ?><br>
    CNH: <?php the_field(‘cnh_do_servidor’); ?><br>
    Nome do conjuge: <?php the_field(‘conjuge_do_servidor’); ?><br>
    Telefone do conjuge: <?php the_field(‘tel_do_conjuge’); ?><br>
    Tem filhos: <?php the_field(‘tem_filhos’); ?><br>
    Número de filhos: <?php the_field(‘num_filhos_servidor’); ?><br>
    Filhos que moram com o servidor: <?php the_field(‘filhos_moram_servidor’); ?><br>
    Pai do servidor: <?php the_field(‘pai_do_servidor’); ?><br>
    Mãe do servidor: <?php the_field(‘mae_do_servidor’); ?><br>
    Naturalidade: <?php the_field(‘naturalidade_do_servidor’); ?> – <?php the_field(‘naturalidade_uf’); ?><br>
    Nacionalidade: <?php the_field(‘nacionalidade_do_servidor’); ?><br>
    Formação: <?php the_field(‘formacao_do_servidor’); ?><br></p>
    <h3>Contatos</h3>
    <p>Endereço: <?php the_field(‘endereço_do_servidor’); ?>, <?php the_field(‘bairro_do_servidor’); ?> – <?php the_field(‘cidade_do_servidor’); ?> – <?php the_field(‘estado_do_servidor’); ?> – Cep: <?php the_field(‘cep_do_servidor’); ?><br>
    Ponto de referência: <?php the_field(‘ponto_de_ref_servidor’); ?><br>
    Telefone fixo: <?php the_field(‘fixo_servidor’); ?><br>
    Celular: <?php the_field(‘celular_servidor’); ?><br></p>

    <h3>Trabalho</h3>
    <p>Local de trabalho:
    <?php $locais = get_field(‘local_de_trabalho_servidor’);

    if( $locais ) :
    foreach ($locais as $l) :
    //setup_postdata($post);
    echo get_the_title($l->ID);
    //wp_reset_postdata();
    endforeach;
    endif; ?>

    <br>
    Cargo: <?php the_field(‘cargo_servidor’) ;?><br>
    Nível de atuação: <?php the_field(‘atuação_servidor’); ?><br>
    Matr. Contra Cheque: <?php if(the_field(‘mat_contra_cheque’)) : the_field(‘mat_contra_cheque’); else: echo ‘ – ‘; endif;?><br>
    Matr. Previdenciária: <?php if(the_field(‘mat_da_previdência’)) : the_field(‘mat_da_previdência’); else: echo ‘ – ‘; endif;?><br></p>

    <?php //endwhile; ?>

    </div>
    <div class=”form item-sis clearfix”>

    <form method=”post” action=”#” id=”post” enctype=”multipart/form-data”>
    <input type=”hidden” name=”fields[posttype]” value=”servidores_post” />
    <input type=”hidden” name=”fields[poststatus]” value=”publish”/>
    <?php
    acf_form(
    array(
    ‘post_id’ => $post_id,
    ‘field_groups’ => array( ‘252,331’ ), //it’s the ID of your custom field Form
    ‘form’ => false,
    )
    );
    ?>
    <button id=”submit_my_image_upload” name=”submit_my_image_upload” type=”submit” value=”Enviar” >Gravar alterações</button>
    </form>

    </div>
    </div>
    </div>

    <div class=”sistema col320 fright borda-total margin-top clearfix”>

    <div class=”side-interno ” >
    <div class=”tit-sidebar margin-bottom clearfix”><span class=”tit-sidebar-icone”><i class=”flaticon-man454″></i></span>Colegas do servidor</div>

    <?php

    $locais = get_posts(array(
    ‘post_type’ => ‘servidores_post’,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘local_de_trabalho_servidor’,
    ‘value’ =>'”‘ . get_the_ID() . ‘”‘,
    ‘compare’=> ‘LIKE’
    )
    )
    ));
    ?>

    <div class=”bloco-side-interno clearfix”>

    <?php
    if( $locais ) :
    foreach ($locais as $key => $value) :

    echo get_the_title($value);

    endforeach;
    endif;
    ?>

    </div>
    </div>
    </div>

    <div class=”sistema col320 fright borda-total margin-top clearfix”>

    <div class=”side-interno ” >
    <div class=”tit-sidebar margin-bottom clearfix”><span class=”tit-sidebar-icone”><i class=”flaticon-unlock35″></i></span>Denúncias do servidor</div>

    <?php

    $denunQuery = new WP_Query(

    array(
    ‘post_type’ => ‘denuncias_post’,
    ‘posts_per_page’ => -1,
    )
    );

    $cpf = get_field(‘cpf_do_servidor’, false, false);
    ?>
    <div class=”bloco-side-interno clearfix”>
    <?php if ( $denunQuery->have_posts() ) : ?>

    <?php while ( $denunQuery->have_posts() ) : $denunQuery->the_post(); $do_not_duplicate = $post->ID; ?>

    <?php if($cpf == get_field(‘cpf_denuncia’)) : ?><div class=”item-sidebar”>” title=”<?php the_title_attribute(); ?>” ><?php the_title(); ?></div><?php endif;?>

    <?php endwhile; ?>
    <?php wp_reset_postdata(); ?>

    <?php else : ?>
    <span class=”alerta-sidebar”><?php _e( ‘O servidor ainda não fez uma denúncia.’ ); ?></span>
    <?php endif; ?>
    </div>
    </div>
    </div>

    </div>
    </section>

    <?php

    // get_template_part(‘parts/servonline’);

    //get_template_part(‘parts/servgeral’);

    //get_template_part(‘parts/mailling’);

    get_template_part(‘parts/links’);

    get_footer(); ?>

    </body>
    </html>

Viewing 1 post (of 1 total)

The topic ‘Problem to print relationship’ is closed to new replies.